VB.net (desktop) context menu assigned to multiple

2019-07-09 01:44发布

问题:

I have two different grid controls on the same form. They share the same context menu. I am having trouble determining which control is the owner when I select the context menu item.

回答1:

SourceControl property on the ContextMenuStrip class will show the last control that caused that menu strip to be shown.



回答2:

The event handler for the MenuItem's Click event will have a Sender parameter. This object should be the control that had the focus when the context menu was displayed.