Enter Departure events (+ favorites) in C #

Source: Internet
Author: User

This article shows you how to implement the carriage return event and the Enter Trigger button in C # WinForm perfect notation

We often have to implement the Enter (Enter) submission feature in C # WinForm, which is quicker than pressing the button trigger manually.

To complete the carriage return Press the button function, only two steps

1. Find the carriage return event

2. Call the corresponding button event in the Carriage return event function

Let's take a look at each:

1. Carriage return Event: We generally use the KeyDown event. Almost all of the components have KeyDown events. The components we choose here may be Form1 or other components such as tabpage1 or DataGridView, which are to be found right here.

2. Call the corresponding button event in the Carriage return event function

The KeyDown event is not specifically set for carriage return, is for all buttons, we also need to make a judgment, and then call the corresponding button event, 1 and 22 steps throughout the code as follows:

private void Form1_keydown (object sender, KeyEventArgs e)

{

if (E.keycode = = Keys.enter)//Determine Enter

{

This.button1_click (sender, E);//Trigger button Event

}

}

After testing, perfect error-free, press ENTER in Form1, Button1 Click event will start execution.

Enter Departure events (+ favorites) in C #

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.