本文介绍了menustrip和toolstripMenuItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个动态填充菜单项的菜单条。

i需要知道点击了哪个菜单项。 ?。

i我使用下面的代码。



Hi

I have a menu strip which is populated menu items dynamically.
i need to know which menu item is being clicked.?.
i am using the below code.

MenuStrip menuStrip=new MenuStrip();

ToolStripMenuItem File = new ToolStripMenuItem();
ToolStripMenuItem Edit = new ToolStripMenuItem();
menuStrip.Items.Add(File);
menuStrip.Items.Add(Edit);

File.DropDown.Click += new System.EventHandler(this.FileMenuClick); 

private void FileMenuClick(object sender, EventArgs e)
        {
            MessageBox.Show("File Menu item clicked"); 
}





此代码告诉我,我只是点击了一个文件菜单项。

但是我想知道点击哪个文件菜单项?..

提前谢谢

Jim



This code gives me that i just clicked a File menu item.
But i want to know which File menu item being clicked?..
Thanks in advance
Jim

推荐答案

private void SubmenuItem_Click(object sender, EventArgs e)
{
    var _targetMenuItem = sender as MenuItem; 
    var _mname = _targetMenuItem.Name;

    switch(_mname) 
     {
        case "File":
MessageBox.Show("File Menu item clicked");
           break;

        case "Edit":
MessageBox.Show("Edit Menu item clicked");
          break;
    
    }
}


这篇关于menustrip和toolstripMenuItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:18