protected override void OnClosing(CancelEventArgs e)
   {   
    if (this.Visible==true)
    { 
 
     e.Cancel = true;    
 //    this.WindowState = FormWindowState.Minimized;
     Hide();
    }
  
    // otherwise, let the framework close the app
   }


----------------------------------------------------------
:窗口中如何实现对窗口右上解的关闭按钮编程 

protected override void Dispose( bool disposing ) 
       { 
          if( disposing ) 
          { 
             if (components != null)  
             { 
                components.Dispose(); 
             } 
          } 
          base.Dispose( disposing ); 
       }

在里面加入你的代码 
------------------------------------------------------------------

const int  SC_MAXIMIZE = 0xF030;
         protected override void WndProc( ref Message msg ) 
         {         
             if ((int)msg.WParam==SC_MAXIMIZE)
             { 
 
                 this.Height=0;
                 return;
             }
              base.WndProc(ref msg); 
         }