{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.components = new Container();
System.Windows.Forms.NotifyIcon notifyicon = new System.Windows.Forms.NotifyIcon(this .components );
notifyicon.Text = "演示創建托盤";
notifyicon.Visible = true;
ResourceManager resourceManager = new ResourceManager("NotifyIcon.Properties.Resources", GetType().Module.Assembly);//從資源文件中添加圖標
notifyicon.Icon = resourceManager.GetObject("icon1") as Icon;
MenuItem menuitem = new MenuItem("退出程序");
notifyicon.ContextMenu = new ContextMenu(new MenuItem[] { menuitem });
menuitem.Click += new EventHandler(menuitem_Click);
notifyicon.MouseClick += new MouseEventHandler(notifyicon_MouseClick);
}
void notifyicon_MouseClick(object sender, MouseEventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
}
void menuitem_Click(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
Application.Exit();
}
}
}