c#给程序添加右键菜单

2024-12-12 17:53:54
推荐回答(3个)
回答1:

NotifyIcon控件有一个属性contextMenuStrip;
在托一个contextMenuStrip(右键菜单)控件;
用NotifyIcon控件的属性contextMenuStrip指向右键菜单的ID; Icon1 = notifyIcon1.Icon;
notifyIcon1.Icon = Icon;

//notifyIcon1.Icon = mNetTrayIcon ;
notifyIcon1.Text = "合同管理系统";
notifyIcon1.Visible = true;

//定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem[] mnuItms = new MenuItem[3];
mnuItms[0] = new MenuItem();
mnuItms[0].Text = "打开系统";
mnuItms[0].Click += new System.EventHandler(this.showMainForm);

mnuItms[1] = new MenuItem("-");

mnuItms[2] = new MenuItem();
mnuItms[2].Text = "退出系统";
mnuItms[2].Click += new System.EventHandler(this.ExitSelect);
mnuItms[2].DefaultItem = true;

notifyiconMnu = new ContextMenu(mnuItms);
notifyIcon1.ContextMenu = notifyiconMnu;

回答2:

http://cn.ziddu.com/downloadfile/273634/reg.zip.html 这个例子应该是你要的效果

回答3:

那就是ContextMenuStrip的项啊,