none
Button behavior

    Question

  • I have a button control on a form. I would like to be able to use the enter key as a short cut instead of clicking the button. I know that it is probably very easy, but I have been completely unable to figure out how to do this.  It would be cool if someone would tell me how to do this with a button

    gwboolean

    Sunday, April 2, 2017 3:36 AM

Answers

  • Hi gwboolean

    This example

    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar = Convert.ToChar(Keys.Enter) Then

    ' All code

    'more code MessageBox.Show("press enter") End If End Sub

    I dont't speak english, I peruvian.

    Test this code

    Regards,


    Si logré resolver tu consulta, no olvides votar como útil y/o marcar como respuesta.


    Sunday, April 2, 2017 3:51 AM
  • I have a button control on a form. I would like to be able to use the enter key as a short cut instead of clicking the button.

    Please see:
    https://msdn.microsoft.com/en-us/library/aa984346(v=vs.71).aspx

    • Marked as answer by gwboolean Sunday, April 2, 2017 4:55 AM
    Sunday, April 2, 2017 4:11 AM

All replies

  • Hi gwboolean

    This example

    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar = Convert.ToChar(Keys.Enter) Then

    ' All code

    'more code MessageBox.Show("press enter") End If End Sub

    I dont't speak english, I peruvian.

    Test this code

    Regards,


    Si logré resolver tu consulta, no olvides votar como útil y/o marcar como respuesta.


    Sunday, April 2, 2017 3:51 AM
  • I have a button control on a form. I would like to be able to use the enter key as a short cut instead of clicking the button.

    Please see:
    https://msdn.microsoft.com/en-us/library/aa984346(v=vs.71).aspx

    • Marked as answer by gwboolean Sunday, April 2, 2017 4:55 AM
    Sunday, April 2, 2017 4:11 AM
  • Thanks Acamar and Brayan  Both approaches work.

    Acamar,

    I feel stupid because I have used this before and should have known without someone having to tell me.

    Brayan

    I assume you read English.  Your approach has 2 caveats.  The first is that the tab must be stopped on the button to execute the routine you posted.  The second is that the message did not show, but I didn't need the message anyway.

    Again, thanks both of you.


    gwboolean

    Sunday, April 2, 2017 4:55 AM