C#实现用Enter键和Tab键同样功能

在Form_Load中输入如下代码:
foreach (Control ctrl  in   this .Controls) 

    
if  ((ctrl  is  TextBox)  ||  (ctrl  is  ComboBox))  // 如果文本框或下拉框放在组合框中,你应该用如groupBox1.TextBox 
    { 
        ctrl.KeyDown 
+=   new  System.Windows.Forms.KeyEventHandler( this .EnterKeyDown); 
    } 
}
然后在EnterKeyDown事件中定义当按下的键为Enter键时,发送Tab键,程序如下:
private   void  EnterKeyDown( object  sender, System.Windows.Forms.KeyEventArgs e) 

    
if (e.KeyCode == Keys.Enter) 
    { 
        System.Windows.Forms.SendKeys.Send(
" {TAB} " ); 
    } 

你可能感兴趣的:(tab)