سلام
من ایده بهتری دارم . ابتدا در یک مدول تابع زیر رو بسازید :
Public Sub IsNumeric4TextBox(ByVal txtToCheck As TextBox, ByVal e As System.Windows.Forms.KeyPressEventArgs, ByVal InsertPlus As Boolean) If e.KeyChar = "." Then e.KeyChar = ","
Dim m = AscW(e.KeyChar)
', 44
'. 46
If m = 46 Then m = 44
Select Case m 'AscW(e.KeyChar)
Case 48 To 57
e.Handled = False
Case 45 ' -
e.Handled = False
Case 44 ' cama
CamaChek = txtToCheck.Text.Split(",")
If CamaChek.Length = 1 Then
e.Handled = False
Else
e.Handled = True
Beep()
End If
Case 8 ' Backspace
e.Handled = False
Case 43
If InsertPlus Then
e.Handled = False
Else
e.Handled = True
End If
Case Else
e.Handled = True
Beep()
End Select
End Sub
سپس در رویداد KeyPress کد زیر را دخل کنید
Private Sub TextBox1_KeyPress_1(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress, TextBox1.KeyPress IsNumeric4TextBox(sender, e)
End Sub
خوبی این روش اینه که میتوانید همه تکست باکسها رو با هم گروه بندی کنید و نمیخواد برای تک تک انها کد بنویسید.
البته تابع بالایی رو میتوانید خودتان اغییر دهید.
من برای زبان هلندی طراحی کردم (مثلا باید . به , تبدیل شود ) و نمیتوان بیشتر از یکی از اینها رو داشت که بسته به نیاز میتوانید تغییر دهید.