WPF RichTextBox appending coloured text

前端 未结 4 1802
谎友^
谎友^ 2021-02-04 01:38

I\'m using the RichTextBox.AppendText function to add a string to my RichTextBox. I\'d like to set this with a particular colour. How can I do this?

4条回答
  •  礼貌的吻别
    2021-02-04 02:23

    the above single line answer:-

      myRichTextBox.AppendText("items", "CornflowerBlue")
    

    is not working.The correct way it should be writen is (i am using VS 2017) :-

        Dim text1 As New TextRange(myRichTextBox.Document.ContentStart, myRichTextBox.Document.ContentEnd)
      myRichTextBox.AppendText("items")
      text1.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.CornflowerBlue) 
    

提交回复
热议问题