//类变量:
private NotifyIcon notifyMonitor;
窗体Load事件中初始化托盘程序
private void Form1_Load(object sender, EventArgs e)
{
notifyMonitor = new NotifyIcon();
notifyMonitor.Visible = true;
notifyMonitor.Text = "Monitor For hjs";
notifyMonitor.BalloonTipText = "Ballo On Tip Text"; //汽泡显示文字
notifyMonitor.ShowBalloonTip(1000); //汽泡显示时间
notifyMonitor.Icon = MyMonitoring.Properties.Resources.backup3; //汽泡图标,使用资源中的图标
notifyMonitor.MouseDoubleClick += Form1_MouseDoubleClick;
gbClose = false; //初始为false,点击关闭时最小化,输入密码后为TRUE,可以关闭程序
}
初始隐藏窗体
private void Form1_Shown(object sender, EventArgs e)
{
//初始隐藏窗体
this.Hide();
}
窗体双击,显示托盘程序
//窗体双击,显示托盘程序
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show(); // 窗体显现
this.WindowState = FormWindowState.Normal; //窗体回复正常大小
}
关闭窗口,释放托盘图标
//关闭窗口
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
//释放托盘图标
notifyMonitor.Dispose();
}