- using System.Resources;
声明变量
- private NotifyIcon nIcon;
构造方法中写入
- public Form3()
- {
- InitializeComponent();
- this.nIcon = new NotifyIcon();
- ResourceManager manager = new ResourceManager(typeof(TestMouseMove.Properties.Resources));
- Icon icon = (Icon)manager.GetObject("me");
- this.nIcon.Text = "黑色头发";//鼠标悬停系统托盘上显示
- this.nIcon.Icon = icon;//图标
- this.nIcon.Visible = true;//设置图标可见
- ContextMenu cm = new ContextMenu();
- cm.MenuItems.Add(new MenuItem("欢迎访问我的博客"));//添加托盘菜单项
- cm.MenuItems.Add(new MenuItem("第二个"));
- cm.MenuItems.Add(new MenuItem("第三个"));
- nIcon.ContextMenu = cm;//托盘菜单项在图标右键时显示
- this.nIcon.ShowBalloonTip(0x2710, "系统托盘提示", "请右键点击图标显示菜单,左键点击访问我的博客。", ToolTipIcon.Info);//托盘图标加载时提示
- nIcon.Click += new EventHandler(this.nIcon_Click);//委托点击事件
- }
写个点击事件
- private void nIcon_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("http://heisetoufa.javaeye.com");
- }