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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping KeyPress

Status
Not open for further replies.

jayscot

MIS
Feb 2, 2001
25
US
I need a way to trap a key from the keypress event.

In VB6 you just set KeyAscii=0. It looks like e.Handled=True should work, but no effect.

Thanks
 
E.handled works for me.

Private Sub txtStart_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs)
Dim txtW As TextBox = sender
Dim KeyAscii As Short = Asc(e.KeyChar)
KeyPressNumberMinus(txtW, KeyAscii)
If KeyAscii = 0 Then
e.Handled = True
End If
End Sub

Post your code. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Sorry, I actually need to trap the keypress from a ComboBox. Where simply placing e.handled=true in the keypress works for a textbox-- does not work for a combobox.

Private Sub ComboBox1_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles ComboBox1.KeyPress

e.Handled = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top