How can you add text to a RichTextBox control and change the font style as you add text?
A:
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.
Rob Lowther
2010-09-24 08:21:56
I do want to add the text programmatically as in youre first example but I want to cahnge the style of the font as the text is being added so that the text box displays the text in a mixed formats (i.e. some words are bold some are not).
gouldos
2010-09-24 08:40:19
+1
A:
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!
gouldos
2010-09-24 09:10:45