Check which submenu item was clicked in context menu strip

后端 未结 5 548
别那么骄傲
别那么骄傲 2021-01-06 05:53

There is a ContextMenuStrip in a grid control.

I have named it as GridContextMenu.

The GridContextMenu is populated with 4 - 5 items using the following code

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 06:12

    You can use Tag for this purpose in case when your should localize your application. Moreover Tag is an object so you can put any tapy of data there. For example Enum type.

    private void SubmenuItem_Click(object sender, EventArgs e)
    {
        var clickedMenuItem = sender as MenuItem; 
        EnumType item = (EnumType)clickedMenuItem.Tag;
    
        switch(item) {
            case TigeItem:
               break;
            case LionItem:
              break;
             ...
        }
    }
    

提交回复
热议问题