private void Form1_Load(object sender, EventArgs e)
{
//添加菜单一
ToolStripMenuItem subItem;
subItem = AddContextMenu("入库", menuStrip1.Items, null);
//添加子菜单
AddContextMenu("添加入库", subItem.DropDownItems, new EventHandler(MenuClicked));
AddContextMenu("入库管理", subItem.DropDownItems, new EventHandler(MenuClicked));
//添加菜单二
subItem = AddContextMenu("出库", menuStrip1.Items, null);
//添加子菜单
AddContextMenu("添加出库", subItem.DropDownItems, new EventHandler(MenuClicked));
AddContextMenu("出库管理", subItem.DropDownItems, new EventHandler(MenuClicked));
}
/// <summary>
/// 添加子菜单
/// </summary>
/// <param name="text">要显示的文字,如果为 - 则显示为分割线</param>
/// <param name="cms">要添加到的子菜单集合</param>
/// <param name="callback">点击时触发的事件</param>
/// <returns>生成的子菜单,如果为分隔条则返回null</returns>
ToolStripMenuItem AddContextMenu(string text, ToolStripItemCollection cms, EventHandler callback)
{
if (text == "-")
{
ToolStripSeparator tsp = new ToolStripSeparator();
cms.Add(tsp);
return null;
}
else if (!string.IsNullOrEmpty(text))
{
ToolStripMenuItem tsmi = new ToolStripMenuItem(text);
tsmi.Tag = text + "TAG";
if (callback != null) tsmi.Click += callback;
cms.Add(tsmi);
return tsmi;
}
return null;
}
void MenuClicked(object sender, EventArgs e)
{
//以下主要是动态生成事件并打开窗体
//((sender as ToolStripMenuItem).Tag)强制转换
ObjectHandle t = Activator.CreateInstance("WinForms", "WinForms.Form2");
Form f = (Form)t.Unwrap();
f.ShowDialog();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有