README.md

December 5, 2022 ยท View on GitHub

TextBox - Only Accept Numbers

Description

This short little code example shows you how to only accept numbers to be inputed into a textbox by using the KeyPress event procedure. This is beginner, but I've seen alot of people that don't know how to do this.

More Info

Submitted On
ByChris Pietschmann
LevelBeginner
User Rating3.9 (27 globes from 7 users)
CompatibilityVB.NET
CategoryControls/ Forms/ Dialogs/ Menus
World.Net (C#, VB.net)
Archive File

Source Code

Private Sub txtHoursDay_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtHoursWeek.KeyPress
''Only accept numbers
If Not e.KeyChar.IsDigit(e.KeyChar.ToString) Then
e.Handled = True
End If
End Sub