Find control that triggered context menu
I have a dialog with an array of TextBox controls. Each of these has the
ContextMenuStrip property set to point at the same context menu control
"ebContextMenu". When the user right-clicks the text box, the context menu
appears, and then the user selects an item. This triggers the Click event
handler for the item.
My question is, in the event handler, how do I figure out which particular
TextBox control was right-clicked to bring up the context menu?
Background Information:
My original approach was to catch the Click event for the text boxes. In
the event handler I checked for the right button and then set the context
menu item's Tag property and triggered the context menu. Then in the Click
event handler for the menu item I could check the Tag property to figure
out which TextBox was clicked.
The problem was, I was not getting right-button events for these controls.
A system-level context menu was popping up instead, so I switched to using
the ContextMenuStrip property. This doesn't give me the chance to set the
Tag property to indicate which TextBox was clicked.
No comments:
Post a Comment