WinForm Setting Control focus

Source: Internet
Author: User

WinForm The default focus setting of the text box after the window is opened, the default focusing to a text box after entering the window, two methods:

① setting TabIndex

Set the TabIndex in the text box property to 0, and the focus is in this text box by default.

②winform's Activated Event

You can get focus by adding textbox1.focus () to the activated event of the form.

Private void Form1_activated (object  sender, EventArgs e) {     textbox1.focus ();} /* */

Http://www.cnblogs.com/roucheng/p/3518068.html

A textbox can have focus. There are several prerequisites:

1. The form to which the textbox belongs (form) is in the operational (active) state. That is, the user selects the form.
2. The Enable property of the TextBox, the Visiable property is true.

Initially thought to add Textbox1.focus () in the form's Load event, the test failed

private void Form1_Load (object sender, EventArgs e)

{

Textbox1.focus ();

}

Since the focus () function is called when the form is loaded, the TextBox has not been successfully displayed to the interface. So it leads to failure.

I test: The author has always been in the Load event to specify the control focus, the effect is not ideal, I did not think because the Load event when the control was not created, so the input focus cannot be set.

Recommendation: http://www.cnblogs.com/roucheng/p/3509606.html

WinForm Setting Control focus

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.