0

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?

RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41
Becca
  • 23
  • 1
  • 3
  • 1
    Set the OK button to have the lowest tab order value. However, being the default button means that if you hit Enter anywhere on the form that button will execute. If it has focus then the space bar can be used as well. – Craig W. Mar 02 '15 at 22:15
  • 1
    Setting the `AcceptButton` should already do this for you. Are you sure no other code is affecting the property? – Dai Mar 02 '15 at 22:16

1 Answers1

9

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

this.ActiveControl = OkButton
RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41
  • After fiddling around with AcceptButton / Cancelbutton, this finally helped me set the default activated button. Thanks a bunch! – wbt11a Jan 08 '16 at 21:46