C#中关于托盘的用法很方便。只要加入一个NotifyIcon,然后指定一个图标Icon,再处理一下事件就可以了。
components = new System.ComponentModel.Container();
menuitemExit = new MenuItem();
menuitemExit.Index = 0;
menuitemExit.Text = "E&xit";
menuitemExit.Click += new EventHandler(menuitem_click_exit);
contextmenu = new ContextMenu();
contextmenu.MenuItems.AddRange(new MenuItem[] { menuitemExit });
notifyicon = new NotifyIcon(this.components);
notifyicon.Icon = TaskWndStudyForm.Properties.Resources.target;
notifyicon.Text = "Text";
notifyicon.Visible = true;
notifyicon.ContextMenu = contextmenu;
private void menuitem_click_exit(object Sender, EventArgs e)
{
Close();
}

本文介绍了如何使用C#创建托盘程序。通过添加NotifyIcon组件并设置图标及上下文菜单,可以轻松实现应用程序最小化到系统托盘的功能。文中还提供了一个简单的退出菜单项示例。
3810

被折叠的 条评论
为什么被折叠?



