MenuStrip添加菜单和子菜单,子菜单添加点击事件
MenuStrip发现没法添加子菜单,为什么会这样。。。
参考文章
1.menustrip 动态添加菜单和子菜单的代码!再问下动态添加事件怎么做
添加菜单和子菜单,事件
private List<TroubleFA.FAparameters> l_LTRepReasonFA = new List<TroubleFA.FAparameters>();
//TroubleFA.FAparameters为类中结构体
/// <summary>
/// 修复原因代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InitialRepairReasonMenuStrip()
{
//为菜单添加子菜单
ToolStripMenuItem mt = new ToolStripMenuItem();//要使用这个类才行
mt.Text = "选择修复原因";
for (int i = 0; i < l_LTRepReasonFA.Count; i++)//修复原因集合的每一项都加到菜单
{
ToolStripMenuItem newnewmt = new ToolStripMenuItem();//孙菜单
newnewmt.Text = l_LTRepReasonFA[i].strTroubleCoding;//内容
newnewmt.DropDownItemClicked += new ToolStripItemClickedEventHandler(mt_DropDownItemClicked);//事件
ToolStripMenuItem newmt = new ToolStripMenuItem();//子菜单
newmt.Text = l_LTRepReasonFA[i].strTroubleName;
newmt.DropDownItemClicked += new ToolStripItemClickedEventHandler(mt_DropDownItemClicked);//事件
if (!String.IsNullOrEmpty(newnewmt.Text))
newmt.DropDownItems.Add(newnewmt);
if (!String.IsNullOrEmpty(newmt.Text))
mt.DropDownItems.Add(newmt);
}
mt.DropDownItemClicked += new ToolStripItemClickedEventHandler(mt_DropDownItemClicked);//菜单事件
//为控件添加菜单
MenuStrip1.Items.Add(mt);
MenuStrip1.Visible = true;
MenuStrip1.Show();
}