Capturing Enter key stroke

  • Thread starter Thread starter alien2_51
  • Start date Start date
A

alien2_51

I have a form with several buttons, I'd like to default to
a specific button on the Enter keypress event, How would I
do this...?
 
alien2_51 said:
I have a form with several buttons, I'd like to default to
a specific button on the Enter keypress event, How would I
do this...?

Assign the button to the form's 'AcceptButton' property.
 
Im not sure what you mean when you say you want to default to a specific
button on the enter keypress. If you mean that when a non specific control
is focused and I press the Enter key, can I invoke a Handler, well you could
do this ?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine("Button1 Pressed")

End Sub

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

Button1_Click(Me, EventArgs.Empty)

End Sub


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
He He, I never noticed that property in the 20 months I've been using .NET,
just goes to show you learn something every day.

:)

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 

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

Back
Top