AcceptButton and CancelButton for Visual Studio 2010

5.1k views Asked by At

Where are the Form Properties for the AcceptButton and CancelButton for Visual Studio 2010? I'd like to set my btnClose as CancelButton and I'd like to set my btnEnter as my AcceptButton.

3

There are 3 answers

3
Luc Morin On BEST ANSWER

The properties you are talking about are AcceptButton and CancelButton on the Form.

Make sure you select the Form in the form designer, and then look in the property panel.

Cheers

1
rizalp1 On

Is this a windows form in VS 2010? Then you would make two buttons and associate actions in the code behind. Make two buttons, btnCancel and btnEnter and to generate codebehind simply double click the buttons in UI and provide the code.

Code for cancel button is something like:

void btnCancel_Close(object sender, System.EventArgs e){
    this.close();
}
1
Dave M On

Make sure your form derives from System.Windows.Forms.Form, then in the designer make sure you have the Form selected. In the Properties Window, the combo box should see something like

Form1 System.Windows.Forms.Form

Then under the Misc Grouping, you should see the AcceptButton and CancelButton properties that you can set to whatever buttons are on your form. Again, make sure the form is the selected component in the designer window.