Vb6 RichTextBox的查找和查找下一个
我只想把这两个Vb6 RichTextBox的查找和查找下一个,vb6,richtextbox,Vb6,Richtextbox,我只想把这两个都改成只有红色 我知道如何更改第一个is,但我不知道如何更改第二个is richTextBox1.Text = "Where there is a will there is way"; 根据报告: 如果找到了搜索的文本,Find方法将突出显示 指定文本并返回第一个字符的索引 突出显示。如果未找到指定的文本,则使用Find方法 返回1 我假设这是一个输入错误,如果找不到文本,返回值是-1而不是1,因此,在您的代码中: RichTextBox1.SelStart = RichTex
都改成只有红色
我知道如何更改第一个is
,但我不知道如何更改第二个is
richTextBox1.Text = "Where there is a will there is way";
根据报告:
如果找到了搜索的文本,Find方法将突出显示
指定文本并返回第一个字符的索引
突出显示。如果未找到指定的文本,则使用Find方法
返回1
我假设这是一个输入错误,如果找不到文本,返回值是-1而不是1,因此,在您的代码中:
RichTextBox1.SelStart = RichTextBox1.Find("is")
RichTextBox1.SelLength = 2
RichTextBox1.SelColor = vbRed
@萨蒂什库马尔:很高兴听到这个消息。请随意点击答案旁边的复选框,将其标记为已接受。看见
Dim idx As Integer
Dim start As Integer
Do
idx = RichTextBox1.Find("is", start) '// First time through start at beginning
If idx = -1 Then Exit Do
RichTextBox1.SelStart = idx
RichTextBox1.SelLength = 2
RichTextBox1.SelColor = vbRed
start = idx + 1 '// Set the start for .Find to the next character
Loop
RichTextBox1.SelLength = 0 ' Clear the selection