在我的Windows窗体应用程序(C#)中,我有这样的代码:
private void frm_main_Resize(object sender, EventArgs e)
{
if ((this.WindowState == FormWindowState.Minimized) && (checkBox1.Checked))
{
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.WindowState = FormWindowState.Minimized;
}
this.Activate();
}
我的publick表单有双击处理程序notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
当最小化的应用程序仍在任务栏中出现时,如何更改?我希望在最小化状态下它只在系统托盘中。为什么这可以解决问题呢?
答案 0 :(得分:2)
我在我的项目中使用了类似的代码,但是你不需要隐藏和显示:
private void frm_main_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized && checkBox1.Checked)
{
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
}
}
还尝试处理MouseClick
事件而不是DoubleClick
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Clicks == 2)
{
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
notifyIcon1.Visible = false;
this.Activate();
}
}