winform最小化到托盘

1.拖取NotifyIcon控件。将该控件的visible设成false.

2.指定NotifyIcon的Icon(很重要,否则最小化后找不到窗口).

3.找到window的SizeChanged事件:

    private void Form1_SizeChanged(object sender, EventArgs e)
    {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.ShowInTaskbar = false; //不显示在系统任务栏
                notifyIcon1.Visible = true; //托盘图标可见
            }
    }

4.找到NotifyIcon控件的单击或者双击事件:

    private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            this.ShowInTaskbar = true;  //显示在系统任务栏
            this.WindowState = FormWindowState.Normal;
            notifyIcon1.Visible = false;
        }

 

posted @ 2014-01-21 20:27  楪夕  阅读(200)  评论(0编辑  收藏  举报