I have a form which users can add controls to and when they right click it brings up a context menu which has an option to display the properties of the control they right clicked on. The problem I am having is trying to decide how to find out what control the user right clicks on since it could be any number of them and then giving that control focus on the form. Does anyone have any good suggestions? Should I just use the (object Sender) portion of a mouse event?
Thanks.
Best Answer
My choice will be using
object Sender
, most straight forward. Though you need to do casting if you want to have operations on the specific control type.UPDATE:
If you have a good naming convention or at least for those form controls which need ContextMenu operations, here's how you can do it:
Attaching mouse click event to specific controls or you can write something to attach to all controls by iteration through the form's
Controls
collection.Then perform different operations or show different context menu for different controls