托盘其实只要把一个你设计好的图标放到属性“ICON”以外,别的就交给代码来完成了。
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true; // 取消关闭窗体
this.Hide();
this.ShowInTaskbar=false;
this.notifyIcon1.Visible = true;//显示托盘图标
}
{
e.Cancel = true; // 取消关闭窗体
this.Hide();
this.ShowInTaskbar=false;
this.notifyIcon1.Visible = true;//显示托盘图标
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.Show();
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
this.Activate();
}
{
this.Show();
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
this.Activate();
}
我相信代码都能看懂吧,接下来就是右键菜单的操作了。其实系统提供了一个菜单操作,我不太喜欢用,我感觉还是下面的比较直接点。
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
this.notifyIcon1.Visible = false;
Application.Exit();
}