السلام عليكم ورحمه الله وبركاته
لاحظت ركودا بسيطا في الاونة الاخيره في أقسام الدوت نت لذا حاولت ان افكر في بعض الطرق لإعطاء هذه الاقسام رونقها وازدهارها من جديد, فكما نرى ان هناك الكثير من الـ Third-Party التي تعمل ادوات لبيئة الدوت نت مثل DevX و telerik وغيرهما لذا فكرت في عمل أدوات مفتوحة المصدر OpenSource Controls فأرجو من الاعضاء التفاعل وانشاء أدوات تخدم المبرمجين العرب والاستفادة من اكوادها.
اقدم اول اداة IPTextBox وهي عبارة عن اداة تسمح بادخال عنوان IP وهذا هو الكود الخاص بها
Public Class IPTextBox
Public ReadOnly Property IP As String
'Get the IP from TextBoxes
Get
If String.IsNullOrEmpty(txtNumber1.Text) AndAlso String.IsNullOrEmpty(txtNumber2.Text) AndAlso String.IsNullOrEmpty(txtNumber3.Text) AndAlso String.IsNullOrEmpty(txtNumber4.Text) Then
Return Nothing
Else
Return String.Format("{0}.{1}.{2}.{3}", txtNumber1.Text, txtNumber2.Text, txtNumber3.Text, txtNumber4.Text)
End If
End Get
End Property
Private Sub txtNumber_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumber1.KeyPress, txtNumber2.KeyPress, txtNumber3.KeyPress, txtNumber4.KeyPress
'Disable all the keys except the digits and backspace
If Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = Chr(8)) Then
e.Handled = True
End If
End Sub
Private Sub txtNumber_TextChanged(sender As Object, e As System.EventArgs) Handles txtNumber1.TextChanged, txtNumber2.TextChanged, txtNumber3.TextChanged, txtNumber4.TextChanged
'Chech whether the current TextBox has 3 digits, if so move the focus into the next TextBox
Dim currentTextBox As TextBox = DirectCast(sender, TextBox)
If currentTextBox.Text.Length = 3 Then
Select Case currentTextBox.Name
Case "txtNumber1"
txtNumber2.Focus()
Case "txtNumber2"
txtNumber3.Focus()
Case "txtNumber3"
txtNumber4.Focus()
End Select
End If
End Sub
Private Sub txtNumber_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtNumber1.Validating, txtNumber2.Validating, txtNumber3.Validating, txtNumber4.Validating
'Check whether the number in the range 0 - 255
Dim currentTextBox As TextBox = DirectCast(sender, TextBox)
Dim number As Short = Convert.ToInt16(If(currentTextBox.Text.Trim().Length = 0, 0, currentTextBox.Text))
If number < 0 OrElse number > 255 Then
MessageBox.Show(String.Format("{0} is not a valid entry. Please specify a value between 0 and 255", number), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
e.Cancel = False
currentTextBox.SelectionStart = 0
currentTextBox.SelectionLength = currentTextBox.Text.Length
currentTextBox.Focus()
End If
End Sub
End Classارفقت المشروع للفائدة