16-12-21, 07:48 AM
(آخر تعديل لهذه المشاركة : 16-12-21, 07:49 AM {2} بواسطة معاند الحظ.)
اخي ابو انس اعتقد ان الحل الذي تريده هو في استخدام كومبوبوكس تملآ عناصره عن طريق استخدام regex
ليبحث عن اقرب التطابقات في نص تكستبوكس او عناصر داتاجريد فيو باستخدام الادخال الذي قمت به
في المثال الذي عملته استخدمت 2 تكستبوكس الاول rtxt وهو الذي استخدم فيه الاكمال التلقائي
والثاني rtxt2 وهو يحوي النص الذي سيعرض الاكمال التلقائي مقترحات الاكمال بناء على النص الموجود فيه
شاهد الفيديو
باختصار جرب الكود التالي
وللعلم فان الكود مجرد محاولة مني ولا اجزم انه هو بالضبط ماتطلبه
لكنه على الاقل قد يكون نقطة بداية لما تريد
جربه اولا في مشروع اختبار لانه لابد ان تحتاج الى تعديل هنا او هناك في الكود
ملاحظة autoComp هو اسم الكومبوبوكس
ليبحث عن اقرب التطابقات في نص تكستبوكس او عناصر داتاجريد فيو باستخدام الادخال الذي قمت به
في المثال الذي عملته استخدمت 2 تكستبوكس الاول rtxt وهو الذي استخدم فيه الاكمال التلقائي
والثاني rtxt2 وهو يحوي النص الذي سيعرض الاكمال التلقائي مقترحات الاكمال بناء على النص الموجود فيه
شاهد الفيديو
باختصار جرب الكود التالي
كود :
Imports System.Text.RegularExpressions
Imports System.Runtime.InteropServices
Public Class Form1
Dim autoComp As New ComboBox
<DllImport("user32.dll")> _
Private Shared Function GetCaretPos(ByRef lpPoint As Point) As Boolean
End Function
Public Function GetCorrectCaretPos() As Point
Dim pt As Point = Point.Empty
If GetCaretPos(pt) Then
Return pt
Else
Return Point.Empty
End If
End Function
Dim curWord As String
Dim spaceKeyHitCounter As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Controls.Add(autoComp)
End Sub
Private Sub rtxt_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles rtxt.KeyDown
If e.KeyCode = Keys.Space Then
If spaceKeyHitCounter < 1 Then
spaceKeyHitCounter += 1
Else
spaceKeyHitCounter = 0
curWord = ""
autoComp.Hide()
End If
ElseIf e.Modifiers = Keys.Control And e.KeyCode = Keys.V Then
My.Computer.Clipboard.Clear()
curWord = curWord.Remove(curWord.Length - 1)
rtxt.SelectionStart -= Len(curWord)
rtxt.SelectionLength = curWord.Length '- 1
rtxt.SelectedText = autoComp.Text
spaceKeyHitCounter = 0
curWord = ""
autoComp.Hide()
ElseIf e.KeyCode = Keys.Back Then
Try
curWord = curWord.Remove(curWord.Length - 1)
Catch ex As Exception
End Try
Else
If CurCharPos = 0 Then
spaceKeyHitCounter = 1
End If
If e.KeyCode = Keys.Enter Then
If CurCharPos = 0 Then
spaceKeyHitCounter = 1
End If
curWord = ""
End If
curWord += Chr(e.KeyCode)
curWord = curWord.Trim()
autoComp.Left = GetCorrectCaretPos().X
autoComp.Top = GetCorrectCaretPos().Y + autoComp.Height - 5
autoComp.Show()
autoComp.BringToFront()
End If
End Sub
Dim CurCharPos As Integer
Private Sub rtxt_TextChanged(sender As Object, e As System.EventArgs) Handles rtxt.TextChanged
CurCharPos = rtxt.GetPositionFromCharIndex(rtxt.GetFirstCharIndexFromLine(rtxt.GetLineFromCharIndex(rtxt.SelectionStart))).X
Dim col As MatchCollection = Regex.Matches(rtxt2.Text, "\b(\w+)\b", RegexOptions.IgnoreCase Or RegexOptions.IgnorePatternWhitespace)
autoComp.Items.Clear()
For Each match As Match In col
If Regex.IsMatch(match.Value, curWord, RegexOptions.IgnoreCase) Then
If Not autoComp.Items.Contains(match.Value) Then
autoComp.Items.Add(match.Value)
End If
autoComp.SelectedIndex = 0
'autoComp.SelectAll()
End If
Next
End Sub
End Classوللعلم فان الكود مجرد محاولة مني ولا اجزم انه هو بالضبط ماتطلبه
لكنه على الاقل قد يكون نقطة بداية لما تريد
جربه اولا في مشروع اختبار لانه لابد ان تحتاج الى تعديل هنا او هناك في الكود
ملاحظة autoComp هو اسم الكومبوبوكس


