|
Thanks! worked like a charm...
|
|
|
|
|
I have a ConstextMenuStrip. It have 3 items that are Test1, Test2, Test3.
But i dont know how to catch event for three items.
Example.When i click on Test1, it raises a message "I love you"
Please help me.
Thanks alot
superdragon
|
|
|
|
|
Assuming you're using vs2005, please follow these steps:
1) Select one item
2) Go to property panel->event tab (that has a lightning icon)
3) Select a click event and double-click on it
4) Go to the source file and fill in the handler function body.
Best,
Jun
|
|
|
|
|
Thanks a lot, now i see how to do with it
superdragon
|
|
|
|
|
Ok. I have an app in C#. It uses a com object in main thread. Then there is a button which calls a method in that com object that takes a long time. So I added a thread (backgroundWorker) which calls that function on that COM object. Trouble is that while the worker thread is working the main still is not responsive! Why is that?!
Please help!
|
|
|
|
|
It will be easier for people to help if you post some relevant code snippets.
Josh
|
|
|
|
|
When you refer to your main thread are you meaning that the GUI is unresponsive? If that's the case then you need to use BeginInvoke from your second thread that calls a method on your main thread that updates the GUI. I am not an expert, but I have implimented it serveral times. I still sometimes have to refer to previous code. Check CP for articles on updating your GUI. This is where I found my information.
www.lovethosetrains.com
|
|
|
|
|
Sounds like you need to do a combination of threading and callback when an invoke is required.
Here's some of what I did to leave my UI reponsive in my first threaded app while katakana and hiragana flashcards were being displayed to the user.
//create a thread and a delegate in my class description
private Thread MyCardDisplayThread = null;
delegate void MyAllPurposeCallBack();
//start the thread in one of my many methods
MyCardDisplayThread = new Thread(new ThreadStart(ShowCharacterList));
MyCardDisplayThread.Start();
//use the delegate to process UI changes
//Note: This method is called inside "ShowCharacterList()" method
private void ShowHiraganaFlashCard()
{
if (this.KanaCardPictureBox.InvokeRequired)
{
//invoke is required so use the delegate to perform the invoke
MyAllPurposeCallBack KanaCardDisplay = new MyAllPurposeCallBack(ShowHiraganaFlashCard);
this.Invoke(KanaCardDisplay);
}
else
{
//invoke is not required or has been achieved and so do what the method
//was designed for in the first place
this.KanaCardPictureBox.Image = new Bitmap(AppPath+"\\"+HiraganaCards[CurrentKanaIndex]);
if (1 == RunningMode)
{
//this isn't visible during Test mode so only do this in flashcard mode
this.RomajiDisplayLabel.Text = null;
}
}
}
For every UI manipulation action that you want to perform while you have a process running on another thread, you have to check for InvokeRequired and then use the callback delegate to perform that invoke if it is required, otherwise do what ever that UI manipulation is intended to do.
Hope this helps!
Mike Poz
|
|
|
|
|
Wait. So I don't get it. You manipulating the UI from the second thread? But my second thread is sitting in a COM call. How can it do anything else? You lost me
|
|
|
|
|
I wrote this as my first line: "Sounds like you need to do a combination of threading and callback when an invoke is required."
I wrote that because you didn't supply code examples to give us the full story. Programming doesn't work like "word math" problems. Post your code. Without it we can really only guess what it is that you're actually trying to do and so can only offer possible solutions.
Mike Poz
|
|
|
|
|
So I dropped a backgroundWorker on my main Form, named bgWorker and added two even handlers:
<br />
private void OnBtnExecute(object sender, DoWorkEventArgs e)<br />
{<br />
bgWorker.RunWorkerAsync();<br />
}<br />
<br />
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)<br />
{<br />
<br />
e.Result = oDCRR.ExecuteEx();<br />
}<br />
<br />
private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)<br />
{<br />
}<br />
|
|
|
|
|
inner wrote: // oDCRR is the COM object that is created in main thread and in this second thread
// does something very long in the ExecuteEx
Okay, so this comment explains the real problem. The main thread is also the UI thread so if you execute a COM process that takes a while to complete, you're litterally blocking the UI thread.
I can't guarantee this will work but you need to take the COM operation of the UI/main thread. I would try something like this as this is similar to what I did on my KanaFlash program:
//in the class declaration
private Thread MyCOMThread = null;
private void OnBtnExecute(object sender, DoWorkEventArgs e)
{
// oDCRR is the COM object that is created in main thread and in this second thread
// does something very long in the ExecuteEx
MyCOMThread = Thread(new ThreadStart(PerformCOMOperation));
MyCOMThread.Start();
}
private void PerformCOMOperation()
{
e.Result = oDCRR.ExecuteEx();
MyCOMThread.Abort();
ProcessResults(whatever you need here...);
}
//create a MyCOMThread complete event results processor here
private void ProcessResults(some param)
{
//process results
}
Hope this helps!
Mike Poz
|
|
|
|
|
Hi,
I am trying to invoke a static method on "a_class" which is derived by "another_class" and the static function I am trying to invoke in "another_class".
The problem is that I am trying to do this by using reflections. And by using reflections on "a_class" I can not see any MethodInfo for any static method declared in "another_class".
I am trying to do something as follows:
//I will be getting a generic collection in this object
object oCollection;
//Getting the type
Type factoryType = BuildManager.GetType("My.NameSpace.Class", true);
//Calling a static function on factoryType
oCollection = factoryType.InvokeMember("GetByFilter",
BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.InvokeMethod |
BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy,
null, null, new object[] { });
Can anybody kindly tell me how can I achive this?
Thanks in advance
Stuck
|
|
|
|
|
I think that getting rid of the DeclaredOnly binding flag should do the trick (assuming that factoryType == typeof(a_class)). DeclaredOnly specifies that the search should not look in base classes for the member.
|
|
|
|
|
Hi Josh,
I really appriciate that you answered my question. I tried by taking off DeclaredOnly BindingFlag but it still didnt work.
Any other suggestion?
By the way, I was able to see the methods declared public in parent class, but I was not able to see the public static method declared in parent class.
Thank you
|
|
|
|
|
You can't.
Static methods only exist in the class where they are declared. They are not inherited.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks alot Guffa for answering!!
seems like I am out of luck
|
|
|
|
|
Does anyone know the attribute decorations that populate the Tasks list at design time?
|
|
|
|
|
What do u want tell me in detail.
|
|
|
|
|
I thought I had.
I have a user control that inherits Panel called GraphicViewer.
I have a collection to populate.
In designer, I want the GraphicViewer Tasks list to be populated with a task that launches the ArrayTypeEditor.
|
|
|
|
|
I have a TreeView where each node has an model object in it's Tag property. When a node is selected, I show that object in a property grid.
There are only two levels to this structure, a Category object has a Name and a collection of Field objects, which is displayed as a Catetory Node with child Field nodes.
-Cat1
--Field1
--Field2
-Cat2
--Field3
--Field4
Problem is, the property grid allows you to modify the Fields collection in the property grid, and I can't identify a property grid event that will let me know that this has happened so that I can update the TreeView.
The Validating event fires when you alter a plain text field in the property grid, but not when a collection is modified.
Has anybody dealt with this before?
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
Probably the safest way to do this is as follows:
Hook into the BeforeSelect event on the Treeview
In your BeforeSelectEventHandler,
move the PropertyGrid.SelectedObject into the prior SelectedNode Tag.
This will ensure that you capture all changes that occured in each object.
|
|
|
|
|
The objects are updated, that's not the problem. The problem is that the object in a Category node has 4 children in it's collection property, but the TreeView doesn't know that it needs to add a 4th child node. I can check the last node for changes when you move to another node, but I'd like to know the instant it happens so there's no confusion looking at the tree view wondering where my new child is. Does that make sense?
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
SO if the user adds or removes items from the collection using the PropertyGrid the PropertyValueChanged event does not fire?
|
|
|
|
|
Nope, sounded reasonable to me too. It fires when you set the property grid's SelectedObject to another object.
Try code model generation tools at BoneSoft.com.
|
|
|
|