Key Press event in vb.net 2005
Hi,
I'm new to .NET, I have a Numeric text box want to accept only numbers. I have put code into KeyDown and KeyPress event. But events are not triggering at all. Any help please?
Below is the code:
<code>
Private Sub txtNumber_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNumber.KeyDown
blnNumericNo = False
If e.KeyCode < Keys.D0 OrElse e.KeyCode > Keys.D9 Then
If e.KeyCode <> Keys.Back Then
blnNumericNo = True
End If
End If
End Sub
Private Sub txtNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumber.KeyPress
' Debug.Print(e.KeyChar)
If Not blnNumericNo Then
e.Handled = True
End If
End Sub
</code>
Last edited by prabhubasoor; December 15th, 2009 at 10:37 PM..
|