Context Menu Strips
-
I have a Windows Form ContextMenuStrip that I use with several controls on my form. The menu items themselves are instances of ToolStripMenuItem. I handle the Click event for each ToolStripMenuItem. My problem is that inside the Click event, the sender is the ToolStripMenuItem, and I seemingly have no way of telling which control was originally right-clicked. I know which menu item was right-clicked, but I don't know the original control that was right-clicked. I hate to create separate instances of ContextMenuStrip, since it is the same menu for all the controls I am working with. How do I "pass-along" the a reference to the original control to the ToolStripMenuItem? Thanks, Mark
-
I have a Windows Form ContextMenuStrip that I use with several controls on my form. The menu items themselves are instances of ToolStripMenuItem. I handle the Click event for each ToolStripMenuItem. My problem is that inside the Click event, the sender is the ToolStripMenuItem, and I seemingly have no way of telling which control was originally right-clicked. I know which menu item was right-clicked, but I don't know the original control that was right-clicked. I hate to create separate instances of ContextMenuStrip, since it is the same menu for all the controls I am working with. How do I "pass-along" the a reference to the original control to the ToolStripMenuItem? Thanks, Mark
Use the
SourceControl
property of theContextMenuStrip
.Eslam Afifi