Monday, February 6, 2012

Textbox for numbers only VB.NET

Sometimes we need to limit our user inputs to only numbers for instance in a quantity input and for that i leave here a tutorial on how to do that in VB.NET.

Code:

Public Class Form1    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57) Or Asc(e.KeyChar) = 8 Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub



End Class


Video tutorial:


No comments:

Post a Comment