How to find the parent form for a ContextMenuStrip

G

Guest

Hi,

I have a ContextMenuStrip that is used on various forms. When somebody opens
the context menu on a specific form (e.g. Form2) and clicks a menu item, I
need to execute some action on that form. Is there a way to determine the
form from which the context menu was invoked in the click event handler?

Usually I do this with Control.FindForm() but that does not work for the
ContextMenu.

Thanks for your help.
 
T

Techno_Dex

Two things to try. First, try the cmsContextMenuStrip.SourceControl, which
should get you the parent of the current context menu. This might be a
ToolStrip or something completely different. The second option is to try
the cmsContextMenuStrip.TopLevelControl. This should get you the Form which
is the top level control not being parented by any other Control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top