【问题标题】:Find and Find Next for RichTextBox查找和查找 RichTextBox 的下一个
【发布时间】:2015-05-20 20:59:53
【问题描述】:
richTextBox1.Text = "Where there is a will there is way";

我只想更改is 的唯一红色。

我知道如何更改第一个is,但我不知道如何更改第二个is

RichTextBox1.SelStart = RichTextBox1.Find("is")
RichTextBox1.SelLength = 2
RichTextBox1.SelColor = vbRed

【问题讨论】:

    标签: vb6 richtextbox


    【解决方案1】:

    根据MSDN Article

    如果找到搜索的文本,Find 方法会突出显示 指定文本并返回第一个字符的索引 突出显示。如果没有找到指定的文本,Find 方法 返回 1。

    我假设这是一个错字,如果找不到文本,则返回 -1 而不是 1,因此,在您的代码中:

    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
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 2016-01-23
    • 2013-06-18
    • 1970-01-01
    相关资源
    最近更新 更多