4

我想选择一个特定的文本行并用蓝色突出显示它,我希望该文本的前景色为白色。我试过了

 this.Select(start, length);
 this.SelectionBackColor = Color.Blue;
 this.SelectionColor = Color.White;

但它不起作用。怎么了?我想模拟当我们通过鼠标选择一些文本时得到的效果,它的背景色变成浅蓝色,里面的文本变成白色。我可以做到这一点

 this.Select(start, length);

但是一旦它失去焦点,选择就会消失,我希望它永久存在。

4

2 回答 2

4

有更简单的方法来为richtextbox中的文本着色:

richtTextBox.SelectionColor = Color.Red;
richTextBox.SelectedText = "Red text";
richtTextBox.SelectionColor = Color.Green;
richTextBox.SelectedText = "Green text";

你得到: 在此处输入图像描述

于 2011-08-12T14:33:57.437 回答
2

尝试做这样的事情:

        this.richTextBox1.SelectionStart = start;
        this.richTextBox1.SelectionLength = length;
        this.richTextBox1.SelectionColor = Color.White;
        this.richTextBox1.SelectionBackColor = Color.Blue;
于 2009-05-26T17:34:23.527 回答