我写了这个函数
private void richAdd(string who, string what)
{
string colorstring = who + " ( " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " ) :";
richTextBox1.Text += colorstring + " " + what + "\r\n\r\n";
richTextBox1.DeselectAll();
richTextBox1.Select(richTextBox1.Find(colorstring), colorstring.Length);
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.DeselectAll();
}
应该用蓝色标记谁+时间,用黑色标记什么。
然而,在第二次使所有文字变成蓝色之后......任何想法都会出现问题吗?
谢谢!
答案 0 :(得分:1)
试
private void richAdd(string who, string what)
{
string colorstring = who + " ( " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " ) :";
richTextBox1.AppendText(colorstring + " " + what + "\r\n\r\n");
richTextBox1.Select(richTextBox1.Text.LastIndexOf(colorstring), colorstring.Length);
richTextBox1.SelectionColor = Color.Blue;
}