setting the formatted text for a RichTextBox control

  • Thread starter Thread starter Ohad Young
  • Start date Start date
O

Ohad Young

Hi,

I was wondering if there is a possibility to update the content of a
RichTextBox control with a mixture of formatted text (for example bold or
underline) containing in one action. I would like to speed things up and
use a StringBuilder to store the text and its formatting instead of doing a
lot of string concatenations using the SelectedText property.

Any ideas?

Thanks in advance, Ohad
 
Hi Ohad,

Well, there is the RichTextBox.SelectedRtf property, if that is what you
mean.
 
Hi,

Thanks for the quick response.
OK, but how do I use it to add formatted text as the following text (I
used HTML tags for formatting):
<P><U>Today's Menu</U></P><P>Hello Mr. <B>Morten
Wennevik</B>.</P><P>Here are the items for today:</P>
<UL><LI>Soup of the day</LI><LI>Fish and Chips</LI> <LI>Ice
cream.</LI></UL>

What I need is the special characters or tags in RTF that stand for
bold, underline, etc.

Thanks again, Ohad
 
Hi,

I don't neet to convert HTML Formatting to RTF one. I can directly use
RTF formatting if I only knew what are the "tags" and add them to the
contents which is aggregated in the StringBuilder class instance and
assign it finally to the RTF property of the RichTextBox control.

I hope iot's clearer now :)

Ohad
 
this is probably not the most efficient way to add text with a specific
formating, but i derived from richtextbox and added this:

//append a String with a specific Font and a linebreak
void WriteLine(String* text, Color color, System::Drawing::Font*
font)
{
int start = this->TextLength; // remember current/start input
position
this->AppendText(text); // write new text with current style
int stop = this->TextLength; // remember new/end input position
this->AppendText(System::Environment::NewLine);

this->SelectionStart = start; // select from start position
this->SelectionLength = stop-start; // to end position
this->SelectionColor = color; // set new style
this->SelectionFont = font;
}
 
Hi,

I used the RichTextBox SelectionFont, SelectionBullet, etc. properties
to format the content.
After achieving the expected result, :), I inspected the complex content
of the Rtf property and decided to give up the idea of using a
StringBuilder + RTF formatting tags.
However, I packaged the code in a user control and it works well besides
the fact that some of the format instructions are ignored (for example
bold font style) for some mysterious reason. The code is exactly the
same only in a UserControl instead of a Form.

Any idea why?

Ohad
 
Back
Top