منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
a AutoComplete Very Simple! - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغات البرمجة الاخرى (http://vb4arb.com/vb/forumdisplay.php?fid=4)
+--- قسم : قسم لغة vb6.0 (http://vb4arb.com/vb/forumdisplay.php?fid=18)
+---- قسم : قسم مكتبة أكواد vb6.0 (http://vb4arb.com/vb/forumdisplay.php?fid=33)
+---- الموضوع : a AutoComplete Very Simple! (/showthread.php?tid=30948)



a AutoComplete Very Simple! - viv - 17-08-19

كود :
                '**************************************
' Name: a AutoComplete Very Simple!
' Description:VERY SIMPLE cut and paste funtion for the Keypress event of a combobox. Just paste this code into a module or form and call the function from the KeyPress event. KeyAscii = AutoComplete(cboCombobox, KeyAscii,Optional UpperCase)
' By: ( . Y . ) (from psc cd)
'**************************************

Option Explicit
Public Const CB_FINDSTRING = &H14C
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Function AutoComplete(cbCombo As ComboBox, sKeyAscii As Integer, Optional bUpperCase As Boolean = True) As Integer
Dim lngFind As Long, intPos As Integer, intLength As Integer
Dim tStr As String
With cbCombo
If sKeyAscii = 8 Then
If .SelStart = 0 Then Exit Function
.SelStart = .SelStart - 1
.SelLength = 32000
.SelText = ""
Else
intPos = .SelStart '// save intial cursor position
tStr = .Text '// save string
If bUpperCase = True Then
.SelText = UCase(Chr(sKeyAscii)) '// change string. (uppercase only)
Else
.SelText = UCase(Chr(sKeyAscii)) '// change string. (leave case alone)
End If
End If

lngFind = SendMessage(.hwnd, CB_FINDSTRING, 0, ByVal .Text) '// Find string in combobox
If lngFind = -1 Then '// if string not found
.Text = tStr '// set old string (used for boxes that require charachter monitoring
.SelStart = intPos '// set cursor position
.SelLength = (Len(.Text) - intPos) '// set selected length
AutoComplete = 0 '// return 0 value to KeyAscii
Exit Function

Else '// If string found
intPos = .SelStart '// save cursor position
intLength = Len(.List(lngFind)) - Len(.Text) '// save remaining highlighted text length
.SelText = .SelText & Right(.List(lngFind), intLength) '// change new text in string
'.Text = .List(lngFind)'// Use this instead of the above .Seltext line to set the text typed to the exact case of the item selected in the combo box.
.SelStart = intPos '// set cursor position
.SelLength = intLength '// set selected length
End If
End With

End Function



RE: a AutoComplete Very Simple! - Ahmed_Mansoor - 18-08-19

السلام عليكم ورحمة الله وبركاته

أهلا بك أخي الكريم , بارك الله فيك وجزاك الله كل خير , كود جميل ومفيد .


RE: a AutoComplete Very Simple! - awidan76 - 07-09-19

جزاك الله خيرا

احترمك


RE: a AutoComplete Very Simple! - ahmed.m - 17-09-19

بوركت عزيزي