在winform程序里实现最小化隐藏到windows右下角

先放notifyIcon和contextmenustrip控件,并设置对于关系

然后

1.关闭事件里,阻止之间关闭按钮(为了使得用户单机右下角的退出时,能够退出,所以必须使用CloseReason属性)
  private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

            if (e.CloseReason == CloseReason.ApplicationExitCall)
            {
                Application.Exit();
            }
            else
            {
                e.Cancel = true;
                this.WindowState = FormWindowState.Minimized;
                this.Hide();
                this.notifyIcon1.Visible = true;
            }

           
        }


2.双击icon还原
  private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
           
              notifyIcon1.Visible = true;
              this.Show();
              this.Activate();
              this.WindowState = FormWindowState.Normal;
        }

3.右下角单机退出时,运行退出
        private void Exit_Click(object sender, EventArgs e)
        { 
            Application.Exit();
        }

posted @ 2011-11-22 10:52  启明星工作室  阅读(4345)  评论(0编辑  收藏  举报