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 に答える