if (E.keycode = = keys.enter) { //this. Selectnextcontrol (this. Activecontrol,true, True, true, true); Sendkeys.send ("{tab}"); // send keystrokes to the active application format: Send ("{tab}");
/// <summary>///control-related methods for form controls/// </summary> Public classcontroltools{PrivateForm frm; Publiccontroltools (Form frm) { This. frm =frm; } /// <summary> ///the carriage return of all child controls on the form is set to tab/// </summary> Public voidentertotab () {frm. KeyPreview=true; frm. KeyPress+=NewKeypresseventhandler (frm_keypress); } /// <summary> ///registering the KeyPress event for a form/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidFrm_keypress (Objectsender, KeyPressEventArgs e) { if(E.keychar = = (Char) keys.enter) {frm. Selectnextcontrol (frm. ActiveControl,true,true,true,true); } } /// <summary> ///sets the carriage return of all child controls (TextBox ComboBox) of a control to tab/// </summary> /// <param name= "Groupcontrol" >Container Control</param> Public voidEntertotab (Control groupcontrol) {foreach(Control controlinchgroupcontrol.controls) {if(Control isTextBox | | Control isComboBox) control. KeyPress+=NewKeypresseventhandler (control_keypress); } } /// <summary> ///registering the control's KeyPress event/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidControl_keypress (Objectsender, KeyPressEventArgs e) { if(E.keychar = = -) {sendkeys.send ("{Tab}"); E.handled=false; } }}
SOURCE reference:
http://www.phpstudy.net/b.php/100776.html WinForm Enter key to tab key to focus transfer method
http://blog.csdn.net/jameshelong/article/details/11947549 on the WinForm window, implement the method to move the cursor to the next control by pressing ENTER (enter)
WinForm enter key to tab key to focus transfer method