This is a migrated thread and some comments may be shown as answers.

How can i add lines with different background colors?

1 Answer 73 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
TOMISLAV
Top achievements
Rank 1
TOMISLAV asked on 07 Sep 2012, 07:23 AM
Hi,

how kann i add lines of text with different background colors to the radrichtextbox ?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 10 Sep 2012, 09:19 AM
Hello Tomislav,

Thank you for writing.

Here is a method that allows you to specify the desired colors and insert the text:
private void InsertTextInDocument(string textToInsert, Color lineColor)
{
    StyleDefinition style = new StyleDefinition();
    style.SetPropertyValue(Span.FontFamilyProperty, "Comic Sans MS");
    style.SetPropertyValue(Span.FontSizeProperty, Unit.PointToDip(16));
    style.SetPropertyValue(Span.ForeColorProperty, Color.Yellow);
    style.SetPropertyValue(Span.HighlightColorProperty, lineColor);
    this.radRichTextBox1.Document.Insert(textToInsert, style);
}

More information about the customization abilities of a Span is available here: http://www.telerik.com/help/winforms/richtextbox-features-document-elements-span.html.

I hope that the provided information addresses your question.
 
Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
TOMISLAV
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or