Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I was wondering if there was a code to make this happen:

 

when I am typing in a text box, then hit ENTER, the app acts as if I clicked a picturebox, and then the operation for if I clicked that picturebox is performed. Thanx.

Posted

In the designer, you have to set KeyPreview property for the form to TRUE.

 

This event will capture the key events:

 

    Private Sub myForm_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
       Console.WriteLine("code = " + e.KeyCode.ToString)
       Console.WriteLine("data = " + e.KeyData.ToString)
       Console.WriteLine("value = " + e.KeyValue.ToString)
       Console.WriteLine("-----------")
   End Sub

 

This will catch all keys hit by the user. I have found, though, if you have a button selected (tabbed on for example) the form will not catch the enter key specifically.

Posted

this will catch enter:

    
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal eventargs As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
       Dim KeyAscii As Short = Asc(eventargs.KeyChar)
       If KeyAscii = 13 Then
'what you want it to do in here.... (operation of when you click picturebox)
       End If
       If KeyAscii = 0 Then
           eventargs.Handled = True
       End If
   End Sub

Posted
thanks for the last code... it worked... the only problem I am having now is that when I click enter it does the operation but it still sends the cursor down a line in the text box... and I want to to stay there.
Posted

try putting the eventsargs.handled = true in the if statement like so below

 

that way it does all the things you want it to but not perform the actual "enter" key and line feed down to the next line

 

 

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal eventargs As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

Dim KeyAscii As Short = Asc(eventargs.KeyChar)

If KeyAscii = 13 Then

'what you want it to do in here.... (operation of when you click picturebox)

eventsarg.handled = true

End If

If KeyAscii = 0 Then

eventargs.Handled = True

End If

End Sub

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...