我编写了以下C#代码,该代码应在任务栏中显示/隐藏我的图标,但在某些情况下不起作用。 如果用户双击系统托盘中的图标,则我的表单会成功显示,但是如果他再次将其最小化并尝试再次双击它(从系统托盘中),它将仅在任务栏中显示一个图标,但表单仍隐藏。
//Function is Being called once a user clicks on my custom minimize button.
private void MinimizeBox_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void NotifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
notifyIcon1.Visible = false;
Activate();
ShowInTaskbar = true;
WindowState = FormWindowState.Normal;
}
//Resize event for my main form
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(500);
this.Hide();
this.ShowInTaskbar = false;
}
}