Change the Enter key to the Tab key to achieve focus Transfer

Source: Internet
Author: User
/// <Summary>
/// Method related to Form Control
/// </Summary>
Public class ControlTools
{
Private Form frm;

Public ControlTools (Form frm)
{
This. frm = frm;
}

/// <Summary>
/// Press enter of all child controls on the form to set it to a Tab
/// </Summary>
Public void EnterToTab ()
{
Frm. KeyPreview = true;

Frm. KeyPress + = new KeyPressEventHandler (frm_KeyPress );
}
/// <Summary>
/// Register the KeyPress event of the form
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void frm_KeyPress (object sender, KeyPressEventArgs e)
{
If (e. KeyChar = (char) Keys. Enter)
{
Frm. SelectNextControl (frm. ActiveControl, true, true );
}
}

/// <Summary>
/// Set the carriage return of all the child controls (TextBox ComboBox) of a control to a Tab
/// </Summary>
/// <Param name = "groupControl"> container control </param>
Public void EnterToTab (Control groupControl)
{
Foreach (Control control in groupControl. Controls)
{
If (control is TextBox | control is ComboBox)
Control. KeyPress + = new KeyPressEventHandler (control_KeyPress );
}
}

/// <Summary>
/// Register the KeyPress event of the control
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void control_KeyPress (object sender, KeyPressEventArgs e)
{
If (e. KeyChar = 13)
{
SendKeys. Send ("{Tab }");
E. Handled = false;
}
}

}

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.