C # WinForm UserControl simulates the AcceptButton function of a form

Source: Internet
Author: User

Many UserControl programs are used, the user will often enter a value after the return of the direct commit operation. For example, the query, enter the query condition, the user would like to see the results of the query, instead of clicking the Query button, but UserControl is not AcceptButton property, that is, you cannot specify the button to trigger after carriage return.

Method One, modify the button property to Pulic

In the Properties window, modify UserControl to specify the modifier of the button as Pulic, and then set the button on the AcceptButton of the form to UserControl.

or modify it in code, that is, in UC. Modify in Designer.cs

// equivalent to modifying modifier in the Properties window // Default Condition // private DevExpress.XtraEditors.SimpleButton btnquery; // Modify to public  Public DevExpress.XtraEditors.SimpleButton Btnquery;
code modifications in UC

The button set to UC in the form

// Form_Load event, after the UC is loaded, specify AcceptButton this. AcceptButton = Uc.btnquery;

Method Two, Entrust

1. First define a button

Button btn;

2. In the Usercontrol_load event, add:

            BTN = new Button ();            Btn. Click + = new EventHandler (tbcquery_commanded);            if (this. Toplevelcontrol is Form) ((Form) this. Toplevelcontrol). AcceptButton = this.btn;

Note: tbcquery_commanded is a query button event

AcceptButton function of UserControl simulation form from C # WinForm program

C # WinForm UserControl simulates the AcceptButton function of a form

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.