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