开发者

Rich Text Box - text coloring error

开发者 https://www.devze.com 2023-02-16 23:51 出处:网络
I wrote this function private void richAdd(string who, string what) { string colorstring = who + \" ( \" + DateTime.Now.ToString(\"dd/MM/yyyy HH:mm:ss\") + \" ) :\";

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

精彩评论

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