Re: Key Stroke Limitations
Re: Key Stroke Limitations
Your on the right track.. however i tend to use the TextBox#_KeyPress event... also your trying to handle the events your self rather than filtering out those you dont want to happen...
So like in this code...
Code:
Private Sub TxtAmounts_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtMaxBulk.KeyPress, TxtMaxSale.KeyPress, TxtMinSale.KeyPress, TxtInstFee.KeyPress, TxtFee.KeyPress
If Not IsDecimalInput(e.KeyChar) Then
e.Handled = True
End If
End Sub
Public Shared Function IsDecimalInput(ByVal Chr As Char) As Boolean
'Checks if the Char code is valid for a Decimal input (Numbers, Decimal point and control codes only)
Select Case Asc(Chr)
Case 32 To 45
Return False
Case 47
Return False
Case 58 To 255
Return False
Case Else
Return True
End Select
End Function
If the key pressed is not a decimal Ie: number, .(decimal point), cursor movement or control key (Bckspc, Del, ent, etc), just set it as handled, there after the built in control code can take care of the keys i allow through..