【RichTextBox】怎么修改部分文字
【RichTextBox】如何修改部分文字?
比方说我的RichTextBox里面现在有3行信息
Good Morning, everyone.
It is time to go to school.
Let us go to lunch.
我只想要把第二行文字加粗,改字体字号,而不影响其他两行文字。
------解决方案--------------------
使用方法selectLine(1);第二行
比方说我的RichTextBox里面现在有3行信息
Good Morning, everyone.
It is time to go to school.
Let us go to lunch.
我只想要把第二行文字加粗,改字体字号,而不影响其他两行文字。
------解决方案--------------------
/// <summary>
/// 选中行
/// </summary>
/// <param name="line">行号,从0开始</param>
private void selectLine(int line)
{
int start = this.richTextBox1.GetFirstCharIndexFromLine(line);
int length = this.richTextBox1.GetFirstCharIndexFromLine(++line);
if (start == -1)
return;
else if (length == -1)
length = this.richTextBox1.TextLength - start;
else
length = length - start;
this.richTextBox1.Select(start, length);
richTextBox1.SelectionFont = new System.Drawing.Font("宋体 ",10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
}
使用方法selectLine(1);第二行