【发布时间】:2011-03-16 12:44:45
【问题描述】:
这个函数是我写的
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();
}
应该将 who+time 涂成蓝色,将 what 涂成黑色。
然而,在第二次之后,它使所有文本变成蓝色......有什么想法可能有问题吗?
谢谢!
【问题讨论】:
-
使用有意义的变量。使用
who、what等变量的坏习惯。 -
它们是有意义的,这个函数在传入的消息事件上执行。 who - 是谁发送了消息。什么 - 是消息中的内容。
标签: c# .net winforms richtextbox