日期:2014-05-18  浏览次数:21053 次

menustrip 动态添加菜单和子菜单的代码!再问下动态添加事件怎么做
int m = 0;//添加5个主菜单每个主菜单有10个子菜单
  for (int a = 0; a < 5; a++)
  {
  ToolStripMenuItem i = new ToolStripMenuItem();
  i.Name = "jiang";
  i.Text = a+"";
  i.Tag = a;
  this.ms1.Items.Add(i);//ms1是menustrip控件名
  for (int z = 0; z < 10; z++) {
  ToolStripMenuItem i1 = new ToolStripMenuItem();
  i1.Name = "bing";
  i1.Text = m+"";
  i1.Tag = "2323";
   //i1.Click+=new EventHandler(i1_Click);


  i.DropDownItems.Add(i1);
  m++;
  }
  }
上面是我写的动态添加菜单项的代码,现在想问问大家谁能告诉我我想点击子菜单的时候获取所点击的子菜单的TEXT值谢谢大家了 我是乞丐把所有分都拿出来了!

------解决方案--------------------
i1_Click(Object sender,EventArgs e)
{
ToolStripMenuItem item = sender as ToolStripMenuItem;
if (item != null)
{
MessageBox.Show(item.Text);
}
}