找一个好看的ICO图标,这是一个ICO的网站:
8,900,000+ free and premium vector icons, illustrations and 3D illustrations
1、放一个notifyIcon1和contextMenuStrip1控件。
2、notifyIcon1属性中,关联加入contextMenuStrip1控件和指定icon图标。
3、notifyIcon1增加事件:notifyIcon1_MouseDoubleClick。
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible)
{
this.WindowState = FormWindowState.Minimized;
this.notifyIcon1.Visible = true;
this.Hide();
}
else
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.Activate();
}
}
4、contextMenuStrip1在菜单中加一个“退出”,点击它,增加事件:ToolStripMenuItem_Click
//MIN WINDOWS
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.notifyIcon1.Visible = false;
this.Close();
this.Dispose();
System.Environment.Exit(0);
}
5、在form1上,加一个事件:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// 注意判断关闭事件reason来源于窗体按钮,否则用菜单退出时无法退出!
if (e.CloseReason == CloseReason.UserClosing)
{
//取消"关闭窗口"事件
e.Cancel = true;
//使关闭时窗口向右下角缩小的效果
this.WindowState = FormWindowState.Minimized;
this.notifyIcon1.Visible = true;
this.Hide();
return;
}
}