برای محدود سازی یک تکست باکس پست های زیادی وجود داره .
Private Sub TextBoxes_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) <> 8 Then
'فقط اجازه ورود اعداد را بدهید
If Not (Char.IsDigit(CChar(CStr(e.KeyChar))) Or e.KeyChar = ".") Then
e.Handled = True
End If
'فقط یک نقطه اعشار مجاز است
If e.KeyChar = "."c AndAlso TryCast(sender, TextBox).Text.IndexOf("."c) > -1 Then
e.Handled = True
End If
End If
End Sub
یا به این روش :
dim N as string = "0123456789."
if instr(n,e.KeyChar )<=0 then e.handled = true
یا این کد :
if not isnumbric(e.KeyChar) and e.KeyChar <>"." then e.handled = true
یا این کد :
Select Case e.KeyChar
Case "*"
e.Handled = True
Case "-"
e.Handled = True
Case "/"
e.Handled = True
Case "!"
e.Handled = True
Case "#"
e.Handled = True
Case "$"
e.Handled = True
Case "%"
e.Handled = True
Case "^"
e.Handled = True
Case "&"
e.Handled = True
Case "("
e.Handled = True
Case ")"
e.Handled = True
Case "+"
e.Handled = True
End Select
If (e.KeyChar >= "0") And (e.KeyChar <= "9") = False Then
e.Handled = True
End If
برای فقط خواندنی کردن تکست باکس هم دوست گرامی ROSTAM2 در پست دوم راهنمایی کردند