checking dynamically which control is clicked
-
I am developing a program in which there is dynamically generation of some fields let us take the example of label control now i dynamically generate them after taking input from user. when the user right click on any label i will show him a context menu through which he can select the font, color etc and on the selection of that a different dialog box will be selected now Actual problem is that after the selection of that color or font i want to know on which label control user has right clicked on how i will get that . sorry for poor english Thanx in advance Regards INAM Inam
-
I am developing a program in which there is dynamically generation of some fields let us take the example of label control now i dynamically generate them after taking input from user. when the user right click on any label i will show him a context menu through which he can select the font, color etc and on the selection of that a different dialog box will be selected now Actual problem is that after the selection of that color or font i want to know on which label control user has right clicked on how i will get that . sorry for poor english Thanx in advance Regards INAM Inam
The default delegate is void Delegate(object sender, EventArgs e) you can get it by casting sender to label
-
I am developing a program in which there is dynamically generation of some fields let us take the example of label control now i dynamically generate them after taking input from user. when the user right click on any label i will show him a context menu through which he can select the font, color etc and on the selection of that a different dialog box will be selected now Actual problem is that after the selection of that color or font i want to know on which label control user has right clicked on how i will get that . sorry for poor english Thanx in advance Regards INAM Inam
If I understand you correctly, you need to know control which triggered context menu when you handle
MenuItem.Click
event. When you handle this eventsender
is a context menu so it wont't help you much. However, if you handleContextMenu.Popup
sender is the control triggering the event. What you can do is this: create a field in the class where you handle eventsobject controlWhichTriggeredEvent;
Then create a handler forContextMenu.Popup
:private void YourContextMenu_Popup(object sender, System.EventArgs e) { controlWhichTriggeredEvent = sender; }
Now when you handle
MenuItem.Click
,controlWhichTriggeredEvent
will contain the latest control clicked by user (you will have to cast it to label of any other control).