Winforms Default Button

8.1k Views Asked by At

I'm working on a form that has two main buttons, "OK" and "Cancel". I have set the "Accept Button" property of the form to be the "OK" button.

Goal: I would like the "OK" button to be default, so that when the form is opened the "OK" button is highlighted and initiates if the enter key is pressed.

Problem: When the form loads, the "Cancel" button is highlighted, until the user clicks anywhere in the form, then the "OK" button becomes highlighted.

Any suggestions?

1

There are 1 best solutions below

1
RagtimeWilly On BEST ANSWER

Set the ActiveControl property to the OK Button in the Form_Load:

this.ActiveControl = OkButton