1

I have a Button in a FlowLayoutPanel that I have a ContextMenuStrip item attached to the MouseDown event. The reason I have it on the mouse down event is that I have drag and drop functionality attached to the button and the flowlayout panel. I need to beable to get to the button from the context menu when a user right clicks on the button.

I getting the right click and moving on from there then I am able to cast the down through the various level to the context menu item but I am unable to then go past the context menu item to the button that the context menu is being bound to on load of the button control.

I have checked the setting for the SourceControl of the button and this is coming back as null.

How can I go about getting the button that the context menu is attached to?

ToolStripItem item = (sender as ToolStripItem);
ContextMenuStrip owner = item.Owner as ContextMenuStrip;
Button btn = owner.SourceControl as Button;
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Sheenie
  • 143
  • 2
  • 9
  • 1
    When showing the `ContextMenuStrip` pass a control as owner: `contextMenuStrip1.Show((Control)sender, e.Location);` then get the `SourceControl` this way: [Determine what control the ContextMenuStrip was used on](http://stackoverflow.com/questions/4886327/determine-what-control-the-contextmenustrip-was-used-on) – Reza Aghaei Oct 05 '16 at 16:06
  • 1
    thank you very much that is exactly what I was missing – Sheenie Oct 06 '16 at 08:17

0 Answers0