设置richTextBox的属性HideSelection = false;
-
///
-
/// 选中行
-
///
-
/// 行号,从0开始
-
private void selectLine(int line)
-
{
-
int a =
this.richTextBox1.GetFirstCharIndexFromLine(line);
-
int b =
this.richTextBox1.GetFirstCharIndexFromLine(++line);
-
if (a ==
-1)
-
return;
-
else
if (b ==
-1)
-
b =
this.richTextBox1.TextLength - a;
-
else
-
b = b - a;
-
this.richTextBox1.Select(a, b);
-
}
RichTextBox单行文本颜色设置
富文本框以指定颜色输出指定文字
//输出消息
-
private void OutMsg(RichTextBox rtb, string msg, Color color)
-
{
-
rtb.Invoke(
new EventHandler(
delegate
-
{
-
rtb.SelectionStart = rtb.Text.Length;
//设置插入符位置为文本框末
-
rtb.SelectionColor = color;
//设置文本颜色
-
rtb.AppendText(msg +
"\r\n");
//输出文本,换行
-
rtb.ScrollToCaret();
//滚动条滚到到最新插入行
-
}));
-
}