新建议Windowsform 应用程序,在 form上添加控件 NotifyIcon 和 contextMunte (加两个Item 分别为 打开、关闭)。
一下是详细代码:
namespace IconDemo
{
public partial class Form1 : Form
{
public Form1()
{
this.ShowInTaskbar = false;
InitializeComponent();
this.notifyIcon1.ContextMenuStrip = contextMenuStrip1;
}
private bool canClose = false;
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
{
if (canClose == false)
{
e.Cancel = true;
this.Hide();
this.Visible = false;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.ShowInTaskbar = true;
this.Show();
if (this.Visible == false)
this.Visible = true;
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.ShowInTaskbar = true;
this.Show();
this.Visible = true;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
canClose = true;
Application.Exit();
}
}
}
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛