我尝试将winform应用程序最小化到系统托盘中,当最小化我的应用程序时,它仍然在任务栏中打开而不是在系统托盘中打开并在几秒钟后自动关闭
我添加了NotifyIcon
控件并注册到Resize
事件:
private void MainWin_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == this.WindowState)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(500);
this.Hide();
}
else if (FormWindowState.Normal == this.WindowState)
{
notifyIcon1.Visible = false;
}
}
答案 0 :(得分:2)
试试这个:
private void MainForm_Resize(object sender, EventArgs e)
{
switch (this.WindowState)
{
case FormWindowState.Maximized:
this.ShowInTaskbar = true;
break;
case FormWindowState.Minimized:
this.ShowInTaskbar = false;
break;
case FormWindowState.Normal:
this.ShowInTaskbar = true;
break;
default:
break;
}
}