• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Making a button on a form the default button (enter key on the keyboard)

In VB.net there is no place I found on the properties window declare a button as the default button like in VB6.0( same as the enter button on the keyboard)

I tried this, Is this the right place (Form Load) for this code? it seems to work okay

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
               Me.AcceptButton = Button1 'enter button
        Me.CancelButton = Button3        'exit button

    End Sub
  • 3
1 Solution
On your form, set the AcceptButton property to the name of your default button.
So your approach was correct. You can either do it in code like you did it, or just do it at design time
ucla11Author Commented:
How would you do at design time?
At design, you can choose "ok" at the option "DialogResult"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now