区别在WinForm中点击关闭还是执行Form.Close()

在C#的WinForm程序中,是用户点击了右上角的“关闭”按钮,还是调用了WinForm.Close()方法。最典型的是要知道点击右上角的“关闭”按钮发出的事件。下面这个方法可以判断这点:

protected override void WndProc(ref Message msg)

        const int WM_SYSCOMMAND = 0x0112; 
        const int SC_CLOSE = 0xF060;  
  
         if (msg.Msg == WM_SYSCOMMAND && ((int)msg.WParam == SC_CLOSE)) 
         { 
                 // Doing Something 

                 return;
         } 
         base.WndProc(ref msg); 
}

posted @ 2011-01-30 14:12  文明的天空  阅读(504)  评论(0编辑  收藏  举报