Foxtable(狐表)用户栏目专家坐堂 → [求助]RichTextBox 控件查找及定位


  共有2805人关注过本帖树形打印复制链接

主题:[求助]RichTextBox 控件查找及定位

帅哥哟,离线,有人找我吗?
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106168 积分:539957 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/11/7 16:22:00 [显示全部帖子]

Dim richTextBox1 As System.Windows.Forms.RichTextBox = e.Form.Controls("Panel1").BaseControl.Controls(0)
Dim f As Font = New Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point)
Dim str As String = "要查找的字符"
Dim pos As Integer = richTextBox1.Find(str)
If pos > 0 Then
    richTextBox1.SelectionStart = pos
        richTextBox1.SelectionLength = str.Length
        richTextBox1.SelectionFont = f
        richTextBox1.SelectionColor = Color.Red
    End If


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106168 积分:539957 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/1/17 19:58:00 [显示全部帖子]

Find(Char[], Int32)

从特定的起始点开始,在 RichTextBox 控件的文本中搜索字符列表中某个字符的第一个实例

循环或者递归处理,从之前查询结果的位置+字长度作为新的起始点开始查询



 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106168 积分:539957 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/1/17 21:17:00 [显示全部帖子]

Dim richTextBox1 As System.Windows.Forms.RichTextBox = e.Form.Controls("Panel1").BaseControl.Controls(0)
Dim f As Font = New Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point)
Dim pos As Integer =0
Dim str As String = "要查找的字符"
pos = richTextBox1.Find(str,pos,0)
do while pos > 0 
    richTextBox1.SelectionStart = pos
        richTextBox1.SelectionLength = str.Length
        richTextBox1.SelectionFont = f
        richTextBox1.SelectionColor = Color.Red
pos = pos + str.Length
pos = richTextBox1.Find(str,pos,0)
loop


 回到顶部