单击文本框并在光标中得到单词 [英] click textbox and get word in cursor

查看:67
本文介绍了单击文本框并在光标中得到单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

单击带有文本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)


这篇关于单击文本框并在光标中得到单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆