WinForm enter key to tab key to focus transfer method

Source: Internet
Author: User

            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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.