winform 我的 文本框很多,我已经 定好了 tabindex 了,我现在想在文本框中 按回车.自动切换到下一个 文本框
winform   我的   文本框很多,我已经   定好了   tabindex   了 
 我现在想在文本框中   按回车.自动切换到下一个   文本框
------解决方案--------------------winform 我的 文本框很多,我已经 定好了 tabindex 了 
 我现在想在文本框中 按回车.自动切换到下一个 文本框   
 -------------------------------------- 
 txt2.fouce 好象是这样的。
------解决方案--------------------方法1: 
 1、请先设置窗体的keyPreView属性为True,确认控件的键盘事件向窗体注册; 
 2、在窗体的KeyPress事件中编写如下代码: 
         private void Form1_KeyPress(object sender, KeyPressEventArgs e) 
         { 
             if (e.KeyChar == (char)13) 
             { 
                 e.Handled = true; 
                 SendKeys.Send( "{TAB} "); 
             } 
         }
------解决方案--------------------方法2:重写键盘命令事件。 
   protected override bool ProcessCmdKey(ref Message msg,Keys keyData) 
   { 
    if ( (!(ActiveControl is Button)) && (keyData==Keys.Up || keyData==Keys.Down || keyData==Keys.Enter)) 
    { 
     if(keyData == Keys.Enter) 
     { 
      System.Windows.Forms.SendKeys.Send( "{TAB} "); 
      return true; 
     } 
     if(keyData==Keys.Down ) 
      System.Windows.Forms.SendKeys.Send( "{TAB} "); 
     else 
      SendKeys.Send( "+{Tab} "); 
     return true; 
    } 
    else 
     return base.ProcessCmdKey(ref msg,keyData); 
   }