Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for F10 in a textbox 1

Status
Not open for further replies.

dynodave

Programmer
Sep 23, 2002
11
GB
how do you check if f10 has been pressed in a textbox using the keypress event
 
Do you want to test for a certain textbox or all textboxes on a form?

If you want to test for the whole form, try this code, otherwise you can just modify for a certain textbox...

Public Sub Form1_KeyPress(ByVal sender as Object, ByVal e as System.Windows.Form.KeyPressEventArgs) Handles MyBase.Keypress
if (Microsoft.VisualBasic.Asc(e.Keychar)) = 121 then
' insert your code
End if
End Sub

Check this link for the ascii chars for all keyboard keys..

 
A side note controls won't fire a Keypress event for function keys or control keys either. Only the form seems to accept these values. To read more on this check out this article.
To get around this and only check to see if F10 was pressed for one text box try this

Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
If stuff Then
If keyData = keyData.F10 Then
MsgBox("F10 was Pressed")
End If
End If
End Function

Private Sub textbox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCatNo.Enter
stuff = True
End Sub

Private Sub textbox2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCatNo.Leave
stuff = False
End Sub


stuff is a global private variable of type boolean. While the focus is on textbox1 the event for F10 will be fired otherwise it won't.

HTH That'l do donkey, that'l do
[bravo] Mark
 
Use the KeyDown Event.

Private Sub txtFileFilter_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFileFilter.KeyDown
if e.KeyCode = Keys.F10 then
MsgBox(e.KeyCode)
end if
End Sub Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks boys, the responses are very much appreciated
 
How do I send a different key when, for example, Enter is pressed, and I want my form to act as if Tab was pressed?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top