I wrote this function
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();
}
which is supposed to color who+time in blue and what in black.
Yet after the second time i开发者_如何学Pythont makes all the text blue... any ideas what could be wrong with it?
Thanks!
try
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;
}
精彩评论