【2011-02-25】 Winfrom 窗体捕获键盘鼠标事件

只需将代码复制到所需窗体下即可。。。。。。。
Winform 窗体捕获键盘鼠标事件
protected   override   bool  ProcessCmdKey( ref  System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)  // 激活回车键
        {
            
int  WM_KEYDOWN  =   256 ;
            
int  WM_SYSKEYDOWN  =   260 ;
            
if  (msg.Msg  ==  WM_KEYDOWN  |  msg.Msg  ==  WM_SYSKEYDOWN)
            {
                
switch  (keyData)
                {
                    
case  Keys.Escape:
                        
if (MessageBox.Show( " 确定要退出么? " , " 信息提示 " ,MessageBoxButtons.YesNo,MessageBoxIcon.Information)  ==  DialogResult.Yes)
                        {
                            
this .Close(); // csc关闭窗体
                        }                        
                        
break ;
                    
case  Keys.Enter:
                        MessageBox.Show(
" wakaka " );
                        
break ;
                }

            }
            
return   false ;
        }

你可能感兴趣的:(键盘鼠标事件)