تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تكست بوكس يسمح بإدخال أرقام فقط أو حروف فقط
#1
الكلاس التالي عبارة عن تكست بوكس يسمح بإدخال أرقام فقط أو حروف فقط و الكلالس ثم توريثه من TextBox الموجود في الدوت نت

الكود :

PHP كود :
Imports System.Globalization

Public Class CairoTextBox
    Inherits TextBox

    Private _textType 
As TextTypes TextTypes.Numbers
    Private _message 
As String String.Empty
 
   Private tip As ToolTip = New ToolTip()

 
   Private Sub ShowTip()
 
       Me.tip.AutomaticDelay 1
        Me
.tip.AutoPopDelay 1000
        Me
.tip.SetToolTip(MeMe._message)
 
       Me.tip.Show(Me._messageMeMyBase.Width 2MyBase.Height)
 
   End Sub

    Private Sub HideTip
()
 
       Me.tip.SetToolTip(MeString.Empty)
 
       Me.tip.AutomaticDelay 1000
        Me
.tip.Hide(Me)
 
   End Sub

    Protected Overrides Sub OnLostFocus
(As EventArgs)
 
       If Not MyBase.DesignMode Then
            Me
.HideTip()
 
       End If
 
       MyBase.OnLostFocus(e)
 
   End Sub

    Protected Overrides Sub OnTextChanged
(As EventArgs)
 
       MyBase.OnTextChanged(e)
 
       Me.ShowText()
 
   End Sub

    Private Sub ShowText
()
 
       If Not MyBase.DesignMode Then
            Dim selection 
As Integer MyBase.SelectionStart
            Dim bool 
As Integer 0
            Dim txt 
As String String.Empty
 
           Dim s As String Me.Text

            For i 
As Integer 0 To s.Length 1
                Dim current 
As Char s(i)
 
               Select Case Me._textType
                    Case TextTypes
.Numbers
                        If Char
.IsNumber(currentThen
                            txt 
+= current
                        Else
                            bool 
+= 1
                        End 
If

 
                   Case TextTypes.Characters
                        If Not Char
.IsNumber(currentThen
                            txt 
+= current
                        Else
                            bool 
+= 1
                        End 
If
 
               End Select

            Next

            If bool 
0 Then
                Me
.Text String.Format(CultureInfo.CurrentCulture"{0}", {txt})
 
               MyBase.SelectionStart selection bool
                Me
.ShowTip()
 
               Return
            End 
If
 
           Me.HideTip()

 
       End If
 
   End Sub

    Public Property TextType 
As TextTypes
        Get
            Return Me
._textType
        End Get
        Set
(value As TextTypes)
 
           Me._textType value
        End Set
    End Property

    Public Property TipMessage 
As String
        Get
            Return Me
._message
        End Get
        Set
(value As String)
 
           Me._message value
        End Set
    End Property

End 
Class

Public 
Enum TextTypes
    Numbers
    Characters
End Enum 

أضف الكلاس لمشروعك
قم بعمل Build لللكلاس
أضف التكست بوكس للفورم

اضبط الحواص التالية:
حدد نوع المدخلات إما حرزف أو أرقام من الصفة TextType
خدد نوع الرسالة التي تريد إظهارها في حالة الخطأ من الصفة TipMessage
مثلا لو نوع المدحلات أرقام فقط ممكن تكون رسالة الخطأ ...... مسموح إدخال أرقام فقط


الكلاس أعلاه ممكن كتابته علي هيئة كلاسان
الكلاس الأول يقبل أرقام فقط
PHP كود :
Imports System.Globalization

Public Class NumbersTextBox
    Inherits TextBox

    Private tip 
As ToolTip = New ToolTip()
 
   Private _message As String "مسموح إدخال أرقام فقط"


 
   Private Sub ShowTip()
 
       Me.tip.AutomaticDelay 1
        Me
.tip.AutoPopDelay 1000
        Me
.tip.SetToolTip(MeMe._message)
 
       Me.tip.Show(Me._messageMeMyBase.Width 2MyBase.Height)
 
   End Sub

    Private Sub HideTip
()
 
       Me.tip.SetToolTip(MeString.Empty)
 
       Me.tip.AutomaticDelay 1000
        Me
.tip.Hide(Me)
 
   End Sub

    Protected Overrides Sub OnLostFocus
(As EventArgs)
 
       If Not MyBase.DesignMode Then
            Me
.HideTip()
 
       End If
 
       MyBase.OnLostFocus(e)
 
   End Sub

    Protected Overrides Sub OnTextChanged
(As EventArgs)
 
       MyBase.OnTextChanged(e)

 
       If Not MyBase.DesignMode Then
            Dim selection 
As Integer MyBase.SelectionStart
            Dim bool 
As Integer 0
            Dim txt 
As String String.Empty
 
           Dim s As String Me.Text
            For i 
As Integer 0 To s.Length 1
                Dim current 
As Char s(i)
 
               If Char.IsNumber(currentThen
                    txt 
+= current
                Else
                    bool 
+= 1
                End 
If
 
           Next

            If bool 
0 Then
                Me
.Text String.Format(CultureInfo.CurrentCulture"{0}", {txt})
 
               MyBase.SelectionStart selection bool
                Me
.ShowTip()
 
               Return
            End 
If
 
           Me.HideTip()

 
       End If
 
   End Sub

    Public Property TipMessage 
As String
        Get
            Return Me
._message
        End Get
        Set
(value As String)
 
           Me._message value
        End Set
    End Property

End 
Class 

الكلاس الثاني يقبل حروف فقط

PHP كود :
Imports System.Globalization

Public Class CharactersTextBox
    Inherits TextBox

    Private tip 
As ToolTip = New ToolTip()
 
   Private _message As String "مسموح إدخال حروف فقط"

 
   Private Sub ShowTip()
 
       Me.tip.AutomaticDelay 1
        Me
.tip.AutoPopDelay 1000
        Me
.tip.SetToolTip(MeMe._message)
 
       Me.tip.Show(Me._messageMeMyBase.Width 2MyBase.Height)
 
   End Sub

    Private Sub HideTip
()
 
       Me.tip.SetToolTip(MeString.Empty)
 
       Me.tip.AutomaticDelay 1000
        Me
.tip.Hide(Me)
 
   End Sub

    Protected Overrides Sub OnLostFocus
(As EventArgs)
 
       If Not MyBase.DesignMode Then
            Me
.HideTip()
 
       End If
 
       MyBase.OnLostFocus(e)
 
   End Sub

    Protected Overrides Sub OnTextChanged
(As EventArgs)
 
       MyBase.OnTextChanged(e)

 
       If Not MyBase.DesignMode Then
            Dim selection 
As Integer MyBase.SelectionStart
            Dim bool 
As Integer 0
            Dim txt 
As String String.Empty
 
           Dim s As String Me.Text
            For i 
As Integer 0 To s.Length 1
                Dim current 
As Char s(i)
 
               If Not Char.IsNumber(currentThen
                    txt 
+= current
                Else
                    bool 
+= 1
                End 
If
 
           Next

            If bool 
0 Then
                Me
.Text String.Format(CultureInfo.CurrentCulture"{0}", {txt})
 
               MyBase.SelectionStart selection bool
                Me
.ShowTip()
 
               Return
            End 
If
 
           Me.HideTip()

 
       End If
 
   End Sub

    Public Property TipMessage 
As String
        Get
            Return Me
._message
        End Get
        Set
(value As String)
 
           Me._message value
        End Set
    End Property

End 
Class 


أتمني أن يكون الكود مفيدا لكم
Retired
الرد }}}
#2
كلاس مهم جداً

شكرا أستاذ silverlight
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [كود] هو في كود يخليني افتح ورقه دخل تكست بوكس وشكران محمد ايمن 3 2,562 19-04-20, 03:07 PM
آخر رد: asemshahen5
Lightbulb [VB.NET] ازالة الصوت عند الضغظ على الانتر للانتقال بين التكست بوكس EYADISMAIL 3 3,233 29-07-19, 03:59 AM
آخر رد: EYADISMAIL
  كود يسمح لك بكتابة احرف فقط في التيكست بوكس honest 17 10,595 25-05-19, 04:12 PM
آخر رد: bakhcha
  كود بسيط لتغيير لون النص والخلفية لكل ليبل وا تيكست بوكس في الفرم honest 4 8,617 03-02-19, 11:07 AM
آخر رد: alshandodi
  كود للانتقال الى التكست بوكس التالي عند الضغط على زر انتر ahmadpal 4 5,244 08-12-18, 02:38 PM
آخر رد: قناص المدينة
  كود سهل ومفيد للبحث عن كلمة في التكست بوكس honest 11 8,333 11-11-18, 01:27 AM
آخر رد: عماد السيد
  [كود] هذا كود للكمبو بوكس يقوم بعرض البيانات داخل التيكست بوكس حسب الرقم احمد عبد الحكيم 5 5,248 11-11-18, 01:24 AM
آخر رد: عماد السيد
Wink كود صغير يقوم بقراءه النص من التكست بوكس برير مسبل 3 4,472 08-08-18, 03:55 PM
آخر رد: alsouf
  السلام عليكم اريد كود لما تكون موجوده التكست بوكس ندير فوقها بطم وفي التنفيذ تطلعلي nosa 0 1,892 11-05-18, 09:36 PM
آخر رد: nosa
Star [كود] كود يسمح لك بكتابه احرف فقط في ال TextBox YousefOkasha 3 3,852 04-05-18, 08:13 PM
آخر رد: YousefOkasha

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم