Color different parts of a RichTextBox string

前端 未结 9 770
暖寄归人
暖寄归人 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:48

    private void Log(string s , Color? c = null)
            {
                richTextBox.SelectionStart = richTextBox.TextLength;
                richTextBox.SelectionLength = 0;
                richTextBox.SelectionColor = c ?? Color.Black;
                richTextBox.AppendText((richTextBox.Lines.Count() == 0 ? "" : Environment.NewLine) + DateTime.Now + "\t" + s);
                richTextBox.SelectionColor = Color.Black;
    
            }
    

提交回复
热议问题