有没有好的联想输入的方法呢?
请大家不吝赐教!
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
Const LB_FINDSTRING = &H18F
Const LB_SETHORIZONTALEXTENT = &H194
Private Sub Form_Load()
List1.AddItem "a"
List1.AddItem "abc"
List1.AddItem "absd"
List1.AddItem "abgtrh"
List1.AddItem "afg"
List1.AddItem "afgh"
'下一句为列表框添加水平滚动条
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 250, 0
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub Text1_LostFocus()
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal Text1.Text)
End Sub
Private Sub Text1_Validate(Cancel As Boolean)
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal Text1.Text)
End Sub
当我回车后,Validate没有触发,而LostFocus触发了。但是如果我是手动移到另一个文本框时就会触发Validate!