WinForm questions about AcceptButton and Cancelebutton

Source: Internet
Author: User


1.Form.acceptbutton Property : Gets or sets the button on the form pressed by the user when the ENTER key is pressed, the button assigned to this property must be on the current form or in the container on the current table . IButtonControl (that is, only the button can use it.)

Private void Form1_Load (object sender, EventArgs e) {This    . button2;     This this. Button3;}

See MSDN

This nature allows you to specify the presets that occur when the user presses the ENTER key in the application. The button assigned to this IButtonControl must be on the current table or in the container on the current table .

You can use this to allow users to simply press ENTER when they're done, instead of clicking on the button with a mouse button to quickly navigate through the simple list of keys.

If the control currently selected on the form suspend the key and handles it, you cannot activate the Accept button. For example, when you select it to insert new line Character into the control, the multiline text block control allows you to press ENTER.

Imagine if the user after the TextBox to fill in the information, without the mouse, press Enter to perform the next move, is not somewhat convenient.

2.Form.cancelbutton : Gets or set the button control that the user presses when the ESC key is pressed. 

3.Form.acceptbutton : Is the button event that you want to perform after you press ENTER, and I actually find that the focal point of this thing on the Form is used on the non- button! with the focus method , it's a lot more bouncy.

4.Form.cancelbutton : Not controlled by the focus of the impact, no matter where you press ESC can work very normal. 
5. The example is as follows:
Static intJ=1;Static intI=1;Static intK = 1;Private voidForm1_Load (Objectsender, EventArgs e) { This. AcceptButton = This. button1; This. Textbox1.focus (); This. Textbox1.select (); This. CancelButton = This. Button3;}Private voidButton1_Click (Objectsender, EventArgs e) {TextBox1.Text ="pressed the button1:"+j.tostring () +"Times"; This. Textbox2.focus ();//this.textbox2.select ();j + +; This. AcceptButton = This. button2;}Private voidButton2_Click (Objectsender, EventArgs e) {TextBox2.Text ="pressed the button2:"+i.tostring () +"Times"; This. Textbox1.focus ();//this.textbox1.select ();i++; This. AcceptButton = This. Button1;}Private voidButton3_Click (Objectsender, EventArgs e) {textbox3.text ="pressed ESC:"+ k.tostring () +"Times"; k++;}
change from Blogger:http://www.dotblogs.com.tw/yc421206/archive/2009/07/28/9710.aspx

WinForm questions about AcceptButton and Cancelebutton

Related Article

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.