110,533
社区成员
发帖
与我相关
我的任务
分享
public void Disply(ref RichTextBox rtb, string strInput, Color fontColor)
{
int p1 = rtb.TextLength; //取出未添加时的字符串长度。
rtb.AppendText(strInput + "\n"); //保留每行的所有颜色。 // rtb.Text += strInput + "\n"; //添加时,仅当前行有颜色。
int p2 = strInput.Length; //取出要添加的文本的长度
rtb.Select(p1, p2); //选中要添加的文本
rtb.SelectionColor = fontColor; //设置要添加的文本的字体色
//rtb.Refresh();
}
private void button1_Click_1(object sender, EventArgs e)
{
string strChars = richTextBox1.Text;
int iOldLength=0;
iOldLength = richTextBox2.Text.Length;
richTextBox2.AppendText(Environment.NewLine + strChars);
if (strChars == "ni")
{
richTextBox2.Select(iOldLength, richTextBox2.Text.Length);
richTextBox2.SelectionColor = Color.Red;
}
else
{
richTextBox2.Select(iOldLength, richTextBox2.Text.Length);
richTextBox2.SelectionColor = Color.Black;
}
}
}