如何更改RichTextBox中某一行的背景颜色?

Ten*_*ere 6 .net winforms c#-4.0

我想改变整行的颜色,无论文本是否存在.这是一些解释图像:

http://img131.imageshack.us/img131/1802/highlightlineqt2.png.

我在这里找到了一些解决方案,但我希望有一个更简单的解决方案.

jwi*_*mer 0

好吧,那么也许这个(在这里找到):

private void richTextBox1_MouseClick(object sender, MouseEventArgs e, Color color)
{
    int firstcharindex = richTextBox1.GetFirstCharIndexOfCurrentLine();
    int currentline = richTextBox1.GetLineFromCharIndex(firstcharindex);
    string currentlinetext = richTextBox1.Lines[currentline];
    richTextBox1.SelectionBackColor = color;
    richTextBox1.Select(firstcharindex, currentlinetext.Length);
}
Run Code Online (Sandbox Code Playgroud)

这段代码应该可以解决你的问题;-)