NotifyIcon notifyIcon;
private void Form1_Load(object sender, EventArgs e)
{
notifyIconShow();
}
void notifyIconShow()
{
this.notifyIcon = new NotifyIcon();
this.notifyIcon.BalloonTipText = "HI!!!";
this.notifyIcon.Text = "HI!!!";
this.notifyIcon.Icon = new System.Drawing.Icon("recherche.ico");
this.notifyIcon.ShowBalloonTip(1000);
//TODO:初始化 notifyIcon菜單
System.Windows.Forms.ContextMenu notifyIconMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem notifyIconMenuItem = new System.Windows.Forms.MenuItem();
notifyIconMenuItem.Index = 0;
notifyIconMenuItem.Text = "展開(Open)";
notifyIconMenuItem.Click += new EventHandler(notifyIconMenuItem1_Click);
notifyIconMenu.MenuItems.Add(notifyIconMenuItem);
System.Windows.Forms.MenuItem notifyIconMenuItem2 = new System.Windows.Forms.MenuItem();
notifyIconMenuItem2.Index = 1;
notifyIconMenuItem2.Text = "結束(Exit)";
notifyIconMenuItem2.Click += new EventHandler(notifyIconMenuItem2_Click);
notifyIconMenu.MenuItems.Add(notifyIconMenuItem2);
this.notifyIcon.ContextMenu = notifyIconMenu;
//this.notifyIcon.Visible = true;
}
void notifyIconMenuItem1_Click(object sender, EventArgs e)
{
this.Show();
WindowState = FormWindowState.Normal;
notifyIcon.Visible = false;
}
void notifyIconMenuItem2_Click(object sender, EventArgs e)
{
notifyIcon.Visible = false;
Application.Exit();
}
private void Form1_Resize(object sender, EventArgs e) //需設定觸發
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
notifyIcon.Visible = true;
}
}
2010年3月31日 星期三
C# 常駐程式
可將執行程式放入常駐程式內!!!
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言