拖一个 notifyIcon控件到界面,名为 notifyIcon1
//窗体对应的事件
#region Form1_SizeChanged
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized) //判断是否最小化
{
this.ShowInTaskbar = false; //不显示在系统任务栏
notifyIcon1.Visible = true; //托盘图标可见
this.notifyIcon1.ShowBalloonTip(1000, this.notifyIcon1.BalloonTipTitle, this.notifyIcon1.BalloonTipText, ToolTipIcon.Info);//显示气泡提示
}
}
#endregion
还可以设置 notifyIcon1 的事件
#region notifyIcon1_DoubleClick
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal;
//notifyIcon1.Visible = false; //托盘图标不可见
this.ShowInTaskbar = true;
}
}
#endregion
#region notifyIcon1_MouseUp
private void notifyIcon1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.notifyIcon1.ShowBalloonTip(1000, "提示:", "系统当前时间:" + DateTime.Now.ToLocalTime().ToString() + "\r\n您设定的时间:" + txtTaskTime.Text, ToolTipIcon.Info);//显示气泡提示
}
}
#endregion
总之,就是改变它在托盘的可见性和在任务栏的可见性。