how do I get the index of a firing context menu item

Posted by fishhead on Stack Overflow See other posts from Stack Overflow or by fishhead
Published on 2010-05-19T02:31:56Z Indexed on 2010/05/19 3:00 UTC
Read the original article Hit count: 265

Filed under:
|
|

I would like to determine the index of the selected context menu item. But I don't want to build a unique eventhandler for each menu item...how do I do this

MenuItem mi=   StatusContextMenu.MenuItems.Add("Set option");
  mi.MenuItems.Add(0,new MenuItem("Set to A", new EventHandler(SetLetter)) );
  mi.MenuItems.Add(1,new MenuItem("Set to B", new EventHandler(SetLetter)));
  mi.MenuItems.Add(2,new MenuItem("Set to C ", new EventHandler(SetLetter)));
  mi.MenuItems.Add(3,new MenuItem("Set to D", new EventHandler(SetLetter)));

private void SetLetter(object sender, System.EventArgs e)
{
  index = ????
}

C#, .net 2.0

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms