private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
//如果鼠标左键单击
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (this.Visibility == Visibility.Visible)
{
this.Visibility = Visibility.Hidden;
}
else
{
this.Visibility = Visibility.Visible;
if (this.WindowState == System.Windows.WindowState.Minimized)
{
this.WindowState = System.Windows.WindowState.Normal;
}
//当窗体点击最小化后,只有显示托盘图标
//但是点击托盘后,他只是显示在任务栏
this.Activate();
//activate后还是在任务栏,而这时我想要的是他还原,原来大小并为我当前焦点 谢谢
}
}
}
/// <summary>
/// 窗体状态改变时候触发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SysTray_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Minimized)
{
//这里实现最小化的时候不在任务栏中显示,而只是显示一个托盘
this.Visibility = Visibility.Hidden;
}
}
去掉if (this.WindowState == System.Windows.WindowState.Minimized)
这个判断,无论如何都执行this.WindowState = System.Windows.WindowState.Normal;
private void SysTray_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Minimized)
{
//这里实现最小化的时候不在任务栏中显示,而只是显示一个托盘
this.Visibility = Visibility.Hidden;
}
else
{
this.Visibility = Visibility.Visible;
}
}