Author | Message | Time |
---|---|---|
-kP-FuZioN | I'm using vb 6 and I want to make some sort of mechanism for autocomplete, like the ones where you type the first part, and then the rest of the word is filled in, but highlighted. I don't know how to highlight things on text boxes. Can someone help me out? | July 11, 2003, 3:02 AM |
iago | To highlight, say, the first 5 characters, use this: text1.selstart = 5 text1.sellength = len(text1.text) - 5 | July 11, 2003, 12:10 PM |
kamakazie | [quote author=iago link=board=5;threadid=1870;start=0#msg14515 date=1057925427] To highlight, say, the first 5 characters, use this: text1.selstart = 5 text1.sellength = len(text1.text) - 5 [/quote] Wouldn't that highlight all the characters after the 5th one? | July 11, 2003, 1:24 PM |
DarkMinion | Yes, selstart should be 0, and sellength should be just 5 if you want the first 5 characters.... | July 11, 2003, 6:12 PM |
iago | That's what I meant to say.. my bad :) | July 11, 2003, 9:12 PM |
ioSys | Mail me and i can send you the code for it. its not that hard. sustanolen@hotmail.com | July 12, 2003, 7:38 AM |
TheMinistered | Here is a combo box autocomplete from extreme vb code library: [code] Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _ ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) _ As Long Private Const CB_FINDSTRING As Long = &H14C Public Sub ComboAutoComplete(ByRef SourceCtl As VB.ComboBox, _ ByRef KeyAscii As Integer, ByRef LeftOffPos As Long) Dim iStart As Long Dim sSearchKey As String With SourceCtl 'If text entered so far matches item(s) in the list, use autocomplete Select Case Chr$(KeyAscii) Case vbBack 'Let backspace characters process as usual; otherwise try to match text Case Else If Chr$(KeyAscii) <> vbBack Then .SelText = Chr$(KeyAscii) iStart = .SelStart If LeftOffPos <> 0 Then .SelStart = LeftOffPos iStart = LeftOffPos End If sSearchKey = CStr(Left$(.Text, iStart)) .ListIndex = SendMessage(.hWnd, CB_FINDSTRING, -1, _ ByVal CStr(Left$(.Text, iStart))) If .ListIndex = -1 Then LeftOffPos = Len(sSearchKey) End If .SelStart = iStart .SelLength = Len(.Text) LeftOffPos = 0 KeyAscii = 0 End If End Select End With End Sub Private Sub Combo1_KeyPress(KeyAscii As Integer) Static iLeftOff As Long ComboAutoComplete Combo1, KeyAscii, iLeftOff End Sub [/code] | July 12, 2003, 12:44 PM |