السلام عليكم
هذا الموضوع استكمال لدورة الاكواد الشاملة
هذا الموضوع خاص بالادوات : اداة ComboBox
بيئة العمل : VB.NET 2019 - يعمل على جميع اصدارات VB.NET
============================================
'5-عمل اكمال تلقائي بطريقة اخرى
كود PHP:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("item1")
ComboBox1.Items.Add("item2")
ComboBox1.Items.Add("item3")
ComboBox1.Items.Add("item4")
ComboBox1.Items.Add("item5")
End Sub
Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
AutoCompleteKeyUp(ComboBox1, e)
End Sub
End Class
Module Module1
Public Sub AutoCompleteKeyUp(ByVal Combo As _
ComboBox, ByVal e As KeyEventArgs)
Dim strTyped As String
Dim intFoundIndex As Integer
Dim objFoundItem As Object
Dim strFoundText As String
Dim strAppendText As String
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, _
Keys.Up, Keys.Delete, Keys.Down, Keys.CapsLock
Return
End Select
strTyped = Combo.Text
intFoundIndex = Combo.FindString(strTyped)
If intFoundIndex >= 0 Then
objFoundItem = Combo.Items(intFoundIndex)
strFoundText = Combo.GetItemText(objFoundItem)
strAppendText = strFoundText.Substring _
(strTyped.Length)
Combo.Text = strTyped & strAppendText
Combo.Text = strTyped & strAppendText
Combo.SelectionStart = strTyped.Length
Combo.SelectionLength = strAppendText.Length
End If
End Sub
End Module
'5-عمل اكمال تلقائي بطريقة اخرى
'6-تغير خلفية الفورم عند كتابة عنصر غير موجود
كود PHP:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("item1")
ComboBox1.Items.Add("item2")
ComboBox1.Items.Add("item3")
ComboBox1.Items.Add("item4")
ComboBox1.Items.Add("item5")
End Sub
Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
If (Me.ComboBox1.FindString(Me.ComboBox1.Text)) _
<> -1 Then Me.ComboBox1.BackColor = Color.Empty _
Else Me.ComboBox1.BackColor = Color.Blue
End Sub
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
ComboBox1.BackColor = Color.Red
For Each s As String In ComboBox1.Items
If ComboBox1.Text.Length <= s.Length _
AndAlso ComboBox1.Text = s.Substring _
(0, ComboBox1.Text.Length) Then
ComboBox1.BackColor = Color.White
End If
Next
End Sub
End Class
'6-تغير خلفية الفورم عند كتابة عنصر غير موجود