【发布时间】:2017-11-23 02:48:37
【问题描述】:
我的 C# winforms 应用程序中有一个 Richtextbox,但无法找到突出显示整行(文本部分 + 任何空格)的方法。我只能使用以下代码突出显示该行上的文本:
firstCharIndex = richTextBox.Text.IndexOf(header);
headerLine = richTextBox.GetLineFromCharIndex(firstCharIndex);
headerLineText = richTextBox.Lines[headerLine];
int lastCharIndex = richTextBox.GetFirstCharIndexFromLine(headerLine + 1);
//richTextBox.Select(firstCharIndex, headerLineText.Length);
richTextBox.Select(firstCharIndex, lastCharIndex - firstCharIndex);
if (richTextBox.SelectionBackColor != System.Drawing.Color.DarkGray)
{
richTextBox.SelectionBackColor = System.Drawing.Color.DarkGray;
}
【问题讨论】:
标签: c# winforms richtextbox