Color different parts of a RichTextBox string

前端 未结 9 666
暖寄归人
暖寄归人 2020-11-22 08:10

I\'m trying to color parts of a string to be appended to a RichTextBox. I have a string built from different strings.

string temp = \"[\" + DateTime.Now.ToSh         


        
9条回答
  •  一生所求
    2020-11-22 08:35

    I have expanded the method with font as a parameter:

    public static void AppendText(this RichTextBox box, string text, Color color, Font font)
    {
        box.SelectionStart = box.TextLength;
        box.SelectionLength = 0;
    
        box.SelectionColor = color;
        box.SelectionFont = font;
        box.AppendText(text);
        box.SelectionColor = box.ForeColor;
    }
    

提交回复
热议问题