|
|
Title | See which word in a RichTextBox the user clicked |
Keywords | RichTextBox, scroll, line, print, preview, click |
Categories | Controls |
|
|
In the control's Click event handler, use the SelStart property to see where the
user clicked.
|
|
Private Sub RichTextBox1_Click()
Dim pos1 As Integer
Dim pos2 As Integer
Dim txt As String
Dim txtlen As Integer
' Find the beginning of the word.
pos1 = RichTextBox1.SelStart
txt = RichTextBox1.Text
If pos1 > 1 Then
Do While Mid$(txt, pos1, 1) <> " "
pos1 = pos1 - 1
If pos1 <= 1 Then Exit Do
Loop
If pos1 > 1 Then pos1 = pos1 + 1
End If
' Find the end of the word.
pos2 = pos1
txtlen = Len(txt)
Do While Mid$(txt, pos2, 1) <> " "
pos2 = pos2 + 1
If pos2 > txtlen Then Exit Do
Loop
If pos2 <= txtlen Then pos2 = pos2 - 1
txt = Mid$(txt, pos1, pos2 - pos1 + 1)
MsgBox txt
End Sub
|
|
|
|
|
|