让TextBox变成具有URL自动完成功能编号:QA003240 建立日期: 2000年8月2日 最后修改日期:2002年3月16日 所属类别: Visual Basic - 标准控件 lecon: 操作系统: WIN9X And WIN2K 编程工具: Visual Basic 问题: 请问VB专家们,我想让一个VB中的TextBox变成具有URL自动完成功能,与IE中的基本一致,应该怎样做,我知道这是装有IE4的WINDOWS系统具有的特殊功能,应该属于系统调用,必须使用API来完成。多谢了! 水平: 高手 回答: 的意见: Private Declare Function SHAutoComplete Lib "Shlwapi.dll" _ (ByVal hWndEdit As Long, ByVal dwFlags As Long) As Long 这个函数可以满足你的要求。如: SHAutoComplete Text1.hWnd, 0
主持人注: 也可以使用一个下拉框或文本框+列表框的方式实现。这样做的好处是下拉框的内容不一定是URL,可以是任意内容。下面是一个用下拉框实现的示例: ' *************Declarations 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 WM_SETREDRAW As Long = &HB& Private Const CB_FINDSTRING As Long = &H14C&
*************Here is the sub that will implement auto search
Public Sub SearchCombo(InControl As Object) On Error GoTo trap
Dim StrPos As Long Dim lPos As Long Dim SearchStr As String
If TypeOf InControl Is ComboBox Then StrPos = InControl.SelStart SearchStr = Left$(InControl.Text, StrPos)
If lPos >= 0 Then InControl.Text = InControl.List(lPos) InControl.ListIndex = lPos End If
With InControl .SelStart = StrPos .SelLength = Len(InControl.Text) End With End If Exit Sub trap: MsgBox Err.Description End Sub
'**************Implement it like this************ Private Sub cboParent_Change() Call SearchCombo(cboParent) '<--pass the combo box to the sub by name End Sub 此问题由vbfan回答。
我说的是键入的地址栏,有时时提示的功能的哪个,带LIST框的!
不是STATUS BAR!
然后使用ComboBox控件。
建立日期: 2000年8月2日 最后修改日期:2002年3月16日
所属类别: Visual Basic - 标准控件 lecon:
操作系统: WIN9X And WIN2K
编程工具: Visual Basic
问题: 请问VB专家们,我想让一个VB中的TextBox变成具有URL自动完成功能,与IE中的基本一致,应该怎样做,我知道这是装有IE4的WINDOWS系统具有的特殊功能,应该属于系统调用,必须使用API来完成。多谢了!
水平: 高手 回答: 的意见:
Private Declare Function SHAutoComplete Lib "Shlwapi.dll" _
(ByVal hWndEdit As Long, ByVal dwFlags As Long) As Long
这个函数可以满足你的要求。如:
SHAutoComplete Text1.hWnd, 0
主持人注:
也可以使用一个下拉框或文本框+列表框的方式实现。这样做的好处是下拉框的内容不一定是URL,可以是任意内容。下面是一个用下拉框实现的示例:
' *************Declarations
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 WM_SETREDRAW As Long = &HB&
Private Const CB_FINDSTRING As Long = &H14C&
*************Here is the sub that will implement auto search
Public Sub SearchCombo(InControl As Object)
On Error GoTo trap
Dim StrPos As Long
Dim lPos As Long
Dim SearchStr As String
If TypeOf InControl Is ComboBox Then
StrPos = InControl.SelStart
SearchStr = Left$(InControl.Text, StrPos)
lPos = SendMessage(InControl.hwnd, CB_FINDSTRING, 0, ByVal SearchStr)
If lPos >= 0 Then
InControl.Text = InControl.List(lPos)
InControl.ListIndex = lPos
End If
With InControl
.SelStart = StrPos
.SelLength = Len(InControl.Text)
End With
End If
Exit Sub
trap:
MsgBox Err.Description
End Sub
'**************Implement it like this************
Private Sub cboParent_Change()
Call SearchCombo(cboParent) '<--pass the combo box to the sub by name
End Sub
此问题由vbfan回答。
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]