Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private startsave As Boolean
Private str As String
Private newline As Boolean
Private oldposi As Long
Private Sub Form_Load()
Dim ret As Long
Dim point As POINTAPI
Form1.Text1.Text = ""
startsave = False
str = ""
SendKeys Space(2)
ret = GetCaretPos(point)
List1.Visible = False
End Sub
Private Sub List1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Or KeyAscii = Asc(Space(1)) Then
List1.Visible = False
SendKeys List1.List(List1.ListIndex)
ElseIf KeyAscii = vbKeyBack Or KeyAscii = vbKeyEscape Then
List1.Visible = False
Text1.SetFocus
End If
End Sub
Private Sub Text1_Change()
Dim midchar As String
If Text1.SelStart >= 1 Then
midchar = Mid(Text1.Text, Text1.SelStart, 1)
End If
If midchar = Space(1) Then
startsave = True
str = ""
End If
If Text1.SelStart > 1 Then
If Mid(Text1.Text, Text1.SelStart - 1, 1) = Chr(10) Then
startsave = True
str = ""
End If
End If
If midchar = "." Then
judgeit (str)
End If
If startsave And midchar <> Space(1) Then
If oldposi < Text1.SelStart Then
str = str & midchar
Else
If Len(str) > 1 Then
str = Left(str, Len(str) - 1)
End If
End If
End If
oldposi = Text1.SelStart
End Sub
Function judgeit(ByVal strtemp As String)
Dim point As POINTAPI
Dim ret As Long
Select Case strtemp
Case "word1": '对word1敏感
ret = GetCaretPos(point)
List1.Visible = True
For i = 0 To 10
List1.AddItem i
Next
List1.Left = Text1.Left + point.x + 5
List1.Top = Text1.Top + point.y + 3
List1.SetFocus
List1.ListIndex = 0
Case "word2": '对word2敏感
ret = GetCaretPos(point)
List1.Visible = True
For i = 10 To 20
List1.AddItem i
Next
List1.Left = Text1.Left + point.x + 5
List1.Top = Text1.Top + point.y + 3
List1.SetFocus
List1.ListIndex = 0
Case Else: 在这里你可以定义别的单词敏感
End Select
End Function