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

Windows Forms -- Default button

Is there a way to set a button on a form to be the default button when the user presses the enter key? That is, without having to capture the key press event on the form?
0
tpatten
Asked:
tpatten
1 Solution
 
iboutchkineCommented:
On Form property use AcceptButton ptoperty

In the designer you can set the forms AcceptButton property to your
button. AcceptButton is when you hit return.

There's also a CancelButton which is when you hit Cancel.

 From codebehind this will look like:

     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As_
      System.EventArgs) Handles MyBase.Load

         Me.AcceptButton = YourAcceptButton
         Me.CancelButton = YourCancelButton

     End Sub
0
 
tpattenAuthor Commented:
See -- that was easy! Thanks.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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