How to Handle 'enter' key in a form

  • Thread starter sravan_reddy001
  • Start date
S

sravan_reddy001

i had designed a win app(an address book)

when the user wants to enter the contact he will type in all the
details and "HE SHOULD CLICK ON THE ADDENTRY BUTTON PROVIDED"

i want to simplify this task for the user by allowing the data to bw
added in database when "HE PRESSED ENTER KEY AFTER ENTERING THE
DETAILS"

how can make a button as default button and that button is should be
activated when we press the ENTER key from keyboard
 
J

Jeroen

A 'System.Windows.Forms.Form' has a property 'AcceptButton'. In the
designer, the property value selection for 'AcceptButton' allows you
to pick any of the buttons on the form. Related you also have a
'CancelButton' property.

Alternatively, you can add an event-handler for the 'KeyDown' or
'KeyPress' events. The argument is of type
'System.Windows.Forms.KeyEventArgs' and thus will tell you what button
(for example: 'enter') was pressed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top