0

I have created a ContextMenuStrip(called MenuPanels) with the idea of creating a right-click menu. I have a TableLayoutPanelwith a Matrix of Panels and I've added a Mouse_Clickevent to every panel, and then placed

if(e.Button == MouseButtons.Right)
{
MenuPanels.Show(Cursor.Position);
}

as part of the event.

And in MenuPanels I've added a Delete option, the idea would be to change the backgroundImage of the panel.

I've read through a lot of other questions that focus on similar facts but haven't been able to get the Panel from with the ContextMenuStrip has been called, as the SourceControl returns null..

I've tried the methods in here.

And also tried to get the SourceControl from the Opening event (has suggested here) but haven't been successful with that either..

You can see the debug here

Community
  • 1
  • 1
J. Pinto
  • 19
  • 9

1 Answers1

1

Don't use the MouseClick event to show the context menu. Instead, set the ContextMenuStrip property of the controls to the instance of the ContextMenuStrip. This will automatically show the context menu strip at the correct location and with the correct source control.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121