我想在窗体上用代码添加一个notifyIcon该怎么添加呀 我是想这样:notifyIcon not1=new notifyIcon; this.Controls.Add(not1);但是不好用呀, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.MenuItem[] mMenuItems = new MenuItem[1]; notifyIcon1 = new System.Windows.Forms.NotifyIcon(); notifyIcon1.Icon = mSmileIcon; notifyIcon1.Text = "在功能表上按一下滑鼠右鍵"; notifyIcon1.Visible = true; //將所有 MenuItem 物件插入陣列並且同時將它們加入到內容功能表。 mMenuItems[0] = new MenuItem("結束", new EventHandler(this.ExitSelect)); System.Windows.Forms.ContextMenu notifyiconMnu = new ContextMenu(mMenuItems); notifyIcon1.ContextMenu = notifyiconMnu; 楼主的代码能编译通过吗添加NotifyIcon 后,要为NotifyIcon的属性Icon添加一个icon图标,并将其Visible属性设为trueNotifyIcon not1 = new NotifyIcon();not1.Icon = new Icon("E:\\notepad.ico");not1.Visible = true; 现在那个控都已经好用了,但是我想把它用代码,写出来,可是在把它向体上加时就出问题了,平时加控都是用this.Controls.Add(not1);这个方法但这次不好用了 NotifyIcon是不能这么用的,你直接拖个NotifyIcon 控件它也不会显示在Form窗口里,你又怎么能用Controls.Add()方法呢如果想用代码写就按照我上面的写法就行了 NotifyIcon不是从Control继承来的,所以不能用Controls.Add方法添加到窗体中,在窗体的代码里,你可以找到这么一句话: private System.ComponentModel.IContainer components = null;你可以用这个components 做为NotifyIcon的容器,而不是通过Controls.Add添加:// Create the NotifyIcon. this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);this.notifyIcon1.ContextMenu = 你的右键菜单;this.notifyIcon1.Icon = 你的iconthis.notifyIcon1.Text = "哈哈"; 关于C#做游戏的一个效率问题 C# 编写局域网通信软件 动态生成dll文件版本号 UltraWinGrid中加入全选的CheckBox C#,winform客户端与web服务器端问题 小弟求教! 怎么刷新当前窗体。。。 c#版本升级问题 在线等.急求 关于深拷贝和浅拷贝的深入问题?!! 我想为什么编译不了C Sharp 三个comboBox级联的问题 所有人进来,再谈对于初学者学习是否跟上时代,看谁观点胜出~~~
private System.Windows.Forms.MenuItem[] mMenuItems = new MenuItem[1];
notifyIcon1 = new System.Windows.Forms.NotifyIcon();
notifyIcon1.Icon = mSmileIcon;
notifyIcon1.Text = "在功能表上按一下滑鼠右鍵";
notifyIcon1.Visible = true; //將所有 MenuItem 物件插入陣列並且同時將它們加入到內容功能表。
mMenuItems[0] = new MenuItem("結束", new EventHandler(this.ExitSelect)); System.Windows.Forms.ContextMenu notifyiconMnu = new ContextMenu(mMenuItems);
notifyIcon1.ContextMenu = notifyiconMnu;
添加NotifyIcon 后,要为NotifyIcon的属性Icon添加一个icon图标,并将其Visible属性设为trueNotifyIcon not1 = new NotifyIcon();
not1.Icon = new Icon("E:\\notepad.ico");
not1.Visible = true;
this.Controls.Add(not1);这个方法但这次不好用了
在窗体的代码里,你可以找到这么一句话:
private System.ComponentModel.IContainer components = null;你可以用这个components 做为NotifyIcon的容器,而不是通过Controls.Add添加:
// Create the NotifyIcon.
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.notifyIcon1.ContextMenu = 你的右键菜单;
this.notifyIcon1.Icon = 你的icon
this.notifyIcon1.Text = "哈哈";