منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : دالة لجعل مربع النص لا يقبل حروف
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
هذا ما فكرت فيه  لكن كله عيب
ارغب  في عند اضافة اي  مربغ نص  يتم عمل الدالة
شكرا

Public Function onlynumeric(ByVal e As String)
        If Not IsNumeric(e) Then
            e = ""
            MsgBox("Please enter numbers only.", vbInformation)

        End If
    End Function
تفضل

كود :
       Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        e.Handled = Char.IsLetter(e.KeyChar)
    End Sub
هذا كود لمربغ نص محدد
انا ارغب في عمل دالة تصلح لاي مربع نص
السلام عليكم ورحمة الله وبركاته
الكود
كود :
Public Function PressOnlyNumeric(ByVal intKeyValue As System.Windows.Forms.KeyPressEventArgs) ' Integer
       Dim chKiy As Char
       chKiy = intKeyValue.KeyChar
       If Not (Char.IsDigit(chKiy) Or chKiy = "." Or Char.IsControl(chKiy)) Then
           MsgBox("غير مسموح بإدخال الحرف .. فضلاً إدخل أرقام فقط", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Critical, "إدخال خاطئ")
           intKeyValue.Handled = True ' إلغاء الحرف المضغوط
       End If

  End Function

ولتنفيذ هضا الإجراء والإستفادة منه نكتب الكود التالي في حدث KeyPress لأي textbox ..


PressOnlyNumeric(e)   ' إدخال أرقام فقط




اقراء هذه الموضوع في هذا الرباط ستجد ما يفيدك في موضوعك
http://arabteam2000-forum.com/index.php?...%85%D8%A9/
جرب هذا الكود لكن اي تكست على الفورم لا يقبل الا ارقاما فقط
وفي حال اردت ان تكتب في بعض مربعات النص عليك استصناءها
PHP كود :
Private Sub Form1_KeyUp(sender As ObjectAs KeyEventArgsHandles Me.KeyUp
        
For Each ctrl As Control In Me.Controls
            
If TypeOf ctrl Is TextBox And Not IsNumeric(ctrl.TextThen
                ctrl
.BackColor Color.LightPink
                ctrl
.Text ""
                
Exit For
            
End If
        
Next ctrl
    End Sub
    
Private Sub Form1_Load(sender As ObjectAs EventArgsHandles MyBase.Load
        KeyPreview 
True
    End Sub 
بالتوفيق
thanks
شكرا لكم
خليها Default = true
Private OnlyNumbers As Boolean = True