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

KeyPress Event Arguments 1

Status
Not open for further replies.

bajo71

Programmer
Joined
Aug 6, 2007
Messages
135
Location
US
Hello,
I'm trying to allow digits, function keys and chr(46) ie '.' to be typed in a text box. However I cannot seem to get the chr(46) inclusion to work. The following works

Private Sub txtStrike_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles txtStrike.KeyPress
If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
End Sub
...but if i add <<Or CharIsPunctuation(chr(46))>> then the text box doesn't allow any typing whatsoever.

Thanks......
 
Try

If Not (Char.IsDigit(e.KeyChar) OrElse Char.IsControl(e.KeyChar)) AndAlso Not e.KeyChar = "."c Then e.Handled = True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top