单击文本框并在光标中得到单词

问题描述:

你好

单击带有文本ix的文本框时,我需要获取光标周围的光标词

因此,例如,如果我有

Hello

I need to get the cursor word that surrounds a cursor when a text-box with text ix clicked

so if for example i have

Hell|o

,那么我需要打个招呼.在这里,管道已用于表示光标

谢谢

, then i need to get the word hello. Here the Pipe has been used to represent the cursor

thanks

谢谢,但是我找到了一个更简单的解决方案
thanks, but i found a simpler solution
Dim intCursor As Integer = txtInput.SelectionStart
            Dim intStart As Int32 = CInt(IIf(intCursor - 1 < 0, 0, intCursor - 1))
            Dim intStop As Int32 = intCursor
            intStop = txtInput.Text.IndexOf(SingleSpace, intCursor)
            intStart = txtInput.Text.LastIndexOf(SingleSpace, intCursor)
            If intStop < 0 Then
                intStop = txtInput.Text.Length
            End If
            If intStart < 0 Then
                intStart = 0
            End If
            debug.print( txtInput.Text.Substring(intStart, intStop - intStart).Trim)