السادة الافاضل
كيف اجعل التكست بوكس يقبل ارقام فقط مع عدم امكانية كتابة العلامة العشرية اكثر من علامة
125.25 صحيحة
12...25 خطأ
شكرا
كود :
Public Class Form1
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Double.TryParse((TextBox1.Text & e.KeyChar), Nothing) Then
e.Handled = True
End If
End Sub
End Class
شكرا علي اهتمامكم
لم نتمكن من كتابة الرقم العشري الفاصلة 12.75
اتمني ان استطيع ان اكتب فاصلة واحدة فقط
جربت الكود مافيه أي مشكلة؟
عفواً، نسيت أن أجعل الـTextBox مرن من حيث المسح و التعديل..
الكود الجديد:
كود :
Public Class Form1
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Decimal.TryParse((TextBox1.Text & e.KeyChar), Nothing) Then
e.Handled = True
End If
If Char.IsControl(e.KeyChar) Then
e.Handled = False
End If
If Char.IsWhiteSpace(e.KeyChar) Then
e.Handled = True
End If
End Sub
End Class
السلام عليكم هذه طريقتي
Dim c As Char
c = e.KeyChar
If Not (Char.IsDigit© Or Char.IsControl©) Then
If Not Textbox1.Text.Contains(".") And c = "." Then
e.Handled = False
Else
e.Handled = True ' annler
End If
End If