开发者

Rich Text Box - text coloring error

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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜