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!

In VB?

Status
Not open for further replies.

kadcore

Programmer
Nov 13, 2001
12
CA
It's funny how I can use simple code in Delphi's Textbox to handle keypress, How about VB.NET (I am new with VB)

In Delphi:

Code from Keypress event:

if Not Key IN (['0'..'9',#8]) then
Key := #0;

Basically, this will only allow numbers to be entered in the text box (and backspace)
 
Private Sub NumbersOnly(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles YourTextBox.Keypress

If e.KeyChar.IsNumber(e.KeyChar) or Asc(e.KeyChar)=Keys.Back Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
 
Thanks for the fast response, this works great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top