* C# WinForm窗口最小化到系统托盘
http://hi.baidu.com/kfxtgtqyapouyze/item/8ccfdcd5a174a7312a35c7c3

 

主要功能:
(1)、程序启动自动隐藏到任务栏右侧通知栏显示。(与系统托盘同义)
(2)、双击系统托盘图标显示、隐藏窗口;
(3)、右击系统托盘图标提供三个菜单选项,“退出”、“隐藏”、“显示”;

 

以上(1)的实现:

private void Form1_SizeChanged(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        this.Hide();
        this.notifyIcon1.Visible = true;
    }
}

 

以上(2)的实现:

右击notifyIcon1 ,选择属性,双击其中DoubleClick,添加相关代码  

private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Normal)
    {
        this.WindowState = FormWindowState.Minimized;
        this.Hide();
    }
    else if (this.WindowState == FormWindowState.Minimized)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
        this.Activate();
    }
}

 

单击显示程序界面:

private void notifyIcon1_Click(object sender, EventArgs e)
{
    this.Visible = true;
    this.WindowState = FormWindowState.Normal;
    this.notifyIcon1.Visible = false;
}

 

相关文章:

  • 2021-12-05
  • 2021-09-19
  • 2021-07-04
  • 2022-02-26
  • 2021-11-17
  • 2021-05-26
猜你喜欢
  • 2021-08-08
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案