点击“X”或“Alt+F4”时,最小化窗口,
不是关闭窗口.

解决方案 »

  1.   


            protected override void WndProc(ref Message m)
            {
                if (!(m.Msg == 0x112 && m.WParam.ToInt32() == 0xF060)) base.WndProc(ref m);
                else this.Hide();
            }
      

  2.   

    //也许不是最好
    1)使用HOOK(钩子函数)监测键盘输入;
    2)符合条件则将窗体最小化(类似于托盘);
      

  3.   

    处理FormClosing事件:e.Cancel=true;
    this.WindowState=FormWindowState.Minimized;
      

  4.   

                if (e.KeyCode == Keys.X || (e.KeyCode == Keys.F4 && e.KeyCode == Keys.Alt))
                {
                    this.WindowState = FormWindowState.Minimized;
                }
      

  5.   

    protected override void guan(ref Message m)
            {
                if (!(m.Msg == 0x112 && m.WParam.ToInt32() == 0xF060))
                    base.guan(ref m);
                else this.Hide();
            }
      

  6.   

      if (e.KeyCode == Keys.X || (e.KeyCode == Keys.F4 && e.KeyCode == Keys.Alt))
                {
                    this.WindowState = FormWindowState.Minimized;
                }
      

  7.   


     protected override void WndProc(ref   Message m)
            {
                const int WM_SYSCOMMAND = 0x0112;
                const int SC_CLOSE = 0xF060;
                const int SC_MINIMIZE = 0xF020;            if (m.Msg == WM_SYSCOMMAND && ((int)m.WParam == SC_MINIMIZE || (int)m.WParam == SC_CLOSE))
                {
                    //最小化到系统栏 
                    this.Hide();
                    return;
                }
                base.WndProc(ref   m);
            }
      

  8.   


            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                e.Cancel = true;
                this.WindowState = FormWindowState.Minimized;
            }
    这种倒是可以,就是它还在任务栏里面,怎么才可以到系统托盘中呢
      

  9.   

    使用notifyIcon控件可以显示到系统托盘中
      

  10.   

    也可以重载dispose方法,因为close方法是调用了dispose方法的
      

  11.   


     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
               if (e.CloseReason ==CloseReason.UserClosing)
               {
                   e.Cancel = true;
                   this.WindowState = FormWindowState.Minimized;
                }         }        private void button1_Click(object sender, EventArgs e)
            {
                this.Dispose();
            }
      

  12.   

    FormClosing结合notifyIcon即可实现了。