I have been reading for many hours now trying to figure out how to properly cast the Context Menu Strip in Visual Studio 2012 using C#. I built a little test application to show you what I am trying to accomplish. Here is a screen shot.
I have assigned the context menu strip to both controls. I can return the control that raised the MenuStrip but if I add another menu item Like in this example (Test) I get "Cant Cast" errors. Here is the code that I am trying to use.
private void testToolStripMenuItem_Click(object sender, EventArgs e)
{
var item = (ToolStripMenuItem)sender;
var menu = (ContextMenuStrip)item.Owner;
MessageBox.Show(menu.SourceControl.Name);
}