Highlight all searched words

后端 未结 6 756
耶瑟儿~
耶瑟儿~ 2020-12-16 00:35

In my RichtextBox, if I have written as below.

This is my pen,
his pen is beautiful.

Now I search word \"is\"

6条回答
  •  太阳男子
    2020-12-16 01:14

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                for (int i = 0; i < richTextBox1.TextLength; i++)
                {
                    richTextBox1.Find(textBox1.Text, i, RichTextBoxFinds.None);
                    richTextBox1.SelectionBackColor = Color.Red;
                }
            }
            else
            {
                for (int i = 0; i < richTextBox1.TextLength; i++)
                {
                    richTextBox1.SelectAll();
                    richTextBox1.SelectionBackColor = Color.White;
                }
            }
        }[lets make it!][1]
    

提交回复
热议问题