突出显示RichTextBox中的特定单词

时间:2014-02-11 09:01:27

标签: richtextbox vb.net-2010 highlighting

我怎么能这样做:我按下一个按钮,然后它发现每个出现的单词让我们说“测试”并将单词的前色改为aqua ...

txtText.Find("dim")
txtText.SelectionColor = Color.Aqua

如果我这样做,它只找到第一次出现,使它成为aqua,如果我再次按下它会转动所有文本。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您可以编写此代码来执行此操作:

首先你需要按钮(FindBUT)和RichTextBox(TextBox)

Public Class Research

Private Sub FindBUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindBUT.Click
    'Check button text
    If FindBUT.Text = ("Find ""dim""") Then
        'Return all text color to black
        TextBox.ForeColor = Color.Black
        'Find "dim" word
        TextBox.Find("dim")
        TextBox.SelectionColor = Color.Aqua
        'change button text to ("Find all")
        FindBUT.Text = ("Find all")
        'Check button text
    ElseIf FindBUT.Text = ("Find all") Then
        'change all text color to Aqua
        TextBox.ForeColor = Color.Aqua
        'change button text to ("Find ""dim"" ")
        FindBUT.Text = ("Find ""dim""")
    End If
End Sub 

结束班

相关问题