How can i track the menu item selection in C#
-
In C++ we have TrackPopupMenuEx() function to displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. How can i track the menu item selection in C#. How can i archive similar functionality in C#. Sample application appreciated.
-
In C++ we have TrackPopupMenuEx() function to displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. How can i track the menu item selection in C#. How can i archive similar functionality in C#. Sample application appreciated.
In c# a context menu will be the similar one. It has a Checked property that you could use: treat the ClickEvent with something like this:
ToolStripMenuItem ts = sender as ToolStripMenuItem;
if (ts.Checked) { ts.Checked = false; }//if it was checked unchekc it
else { ts.Checked = true; }//else check itNow you can use a foreach or something to retrive the checked items. Something like:
foreach (ToolStripMenuItem item in contextMenuStrip1.Items)
{
if(item.Checked)//do stuff
}