【发布时间】:2017-02-17 17:12:38
【问题描述】:
当用户最小化或关闭应用程序时,我试图隐藏应用程序。然后,如果他单击应用程序的通知图标,它应该会再次显示。我试过这段代码:
private void openForm()
{
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
this.Show();
}
private void closeForm(string text)
{
if (text != "")
{
notifyIcon.BalloonTipText = text;
notifyIcon.ShowBalloonTip(30);
}
this.Hide();
}
private void Main_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.closeForm("Click here to access Spotify Extender again!");
}
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == System.Windows.Forms.CloseReason.UserClosing)
{
e.Cancel = true;
this.closeForm("Click here to access Spotify Extender again!");
}
}
private void notifyIcon_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
this.openForm();
}
关闭部分工作正常,应用程序注册了对图标的点击,但我在再次打开应用程序时遇到了巨大的麻烦。首先,当点击通知图标时,应用程序没有出现,没有焦点,只有任务栏图标可见。如果我点击它,它什么也不做,如果我第二次点击它,它会调用 closeForm() 方法。对这家伙有什么想法吗?我的目标是,单击通知图标后,它应该在任务栏中可见,对用户可见->单击后最顶部(通常不可见)。提前致谢!
【问题讨论】:
-
@HansPassant 我想我这样做...
标签: c# notifyicon