gouldos
gouldos

Reputation: 1153

Editing WinForms RichTextBoxControl C#

How can you add text to a RichTextBox control and change the font style as you add text?

Upvotes: 2

Views: 91

Answers (2)

gouldos
gouldos

Reputation: 1153

Found an excellent library on Code Project which provides an RTFStringBuilder which allows the settings of formatting as the stringbuilder is built up. Setting the RichTextBox's RTF property to the RTFStringBuilder.ToString() does just the job I need. Thanks seeblunt!

Upvotes: 1

Rob Lowther
Rob Lowther

Reputation: 371

Assuming you mean add text programmatically....

RichTextBox myTB = new RichTextBox();

myTB.Text += "Some text";

-- or --

myTB.AppendText("Some other Text");

As for changing the font, you could add an event handler to your richtextbox to get notified when the text changes.

myTB.TextChanged += new EventHandler(myTB_TextChanged);

and set the font of myTB in that event handler.

Just a thought.

Upvotes: 0

Related Questions