gingo
gingo

Reputation: 488

How to add a rtf formatting in the text string for a Richt Text Box?

In a .NET project I have a long plain text build as concatenation of several strings

StringLongText = text1 + text2 + ... + textN

each string "textX" is the result of an evaluation. At the end of a started process, I show the result in a RichTextBox doing simply:

rtfTxt.Text = StringLongText

All works fine, but I am not able to add any text formatting in the previous text1, text2, textN blocks.

For example I would like to write some words in bold or italic including the formatting directly in the strings before concatenating them.

Doing

text1 = "This is some {\b bold} text"
rtfTxt.Text = text1

did not work.

Any suggestion? Thank you for your help.

Upvotes: 5

Views: 19557

Answers (2)

Tilak
Tilak

Reputation: 1

Just write required content with formatting to RTF File. Load RTF file in richtextbox. Verify. Read RTF content into the textbox. Put textbox content to RTF as:

Richtext.rtf = textbox1.text; // (which is textual content)

Upvotes: 0

Danilo Vulović
Danilo Vulović

Reputation: 3063

rtfTxt.Rtf = @"{\rtf1\ansi This is some \b bold\b0 text.}";

Upvotes: 8

Related Questions