【问题标题】:Rich Text Box - text coloring error富文本框 - 文本着色错误
【发布时间】: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 涂成黑色。

然而,在第二次之后,它使所有文本变成蓝色......有什么想法可能有问题吗?

谢谢!

【问题讨论】:

  • 使用有意义的变量。使用 whowhat 等变量的坏习惯。
  • 它们是有意义的,这个函数在传入的消息事件上执行。 who - 是谁发送了消息。什么 - 是消息中的内容。

标签: c# .net winforms richtextbox


【解决方案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;
    }

【讨论】:

    猜你喜欢
    • 2013-11-06
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2010-12-13
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多