Format text in a Rich Text Box Control

I am using a Rich Text Box control in an application being developed in Visual C++ 2005 Express.

How can I format the strings that appear in the box?

For example, some of the lines I want to appear bolded and underlined to make them stand out from the rest while the remainder appear as plain text.
LVL 1
jindaleeAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
Example:

  RichTextBox __gc* rtb = __gc new RichTextBox();
    Font __gc* font = __gc new Font(S"Tahoma", 10, (FontStyle::Underline | FontStyle::Bold));
    rtb->SelectionStart = 10;
    rtb->SelectionLength = 20;
    rtb->SelectionFont = font;

Bob
0
 
jindaleeAuthor Commented:
I just noticed that I set my skill level at Intermediate. I've been programming C++ for years but have only started using the Visual Studio 2005 in the last couple of months. I've previously been using Visual C++ 6 because my employers didn't see the need to upgrade me! So my skill level for Visual Studio 2005 should be beginner!

So a dumb question, a real newbie question in fact.

Where do I put this code? Forgive my ignorance :(
0
 
Bob LearnedCommented:
How are you adding (or want to add) text to the RichTextBox control?  How do you want to highlight only certain text?

Bob
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jindaleeAuthor Commented:
Please ignore the comment added at 0825am. A junior colleague decided to do something he thought was funny!

As for adding to the control, select the control in the properties where it says 'String[] Array" and then pasted.

I only need to bold and underline the occasionalline that is a paragraph header.

The text is to be read only.
0
 
jindaleeAuthor Commented:
I'm adding the control in the Designer and setting values through the properties
0
 
Bob LearnedCommented:
The RichTextBox properties won't let you apply formatting through the designer.  You need to come up with code to change the SelectionStart and SelectionLength properties and then apply a font with the SelectionFont property.  The trick is find the paragraph header, and that is not so straight forward.  The RichTextBox does give you the Find method, so that you can find and highlight text, but that means that you need to determine the text that makes up a paragraph header.

Bob
0
 
jindaleeAuthor Commented:
Thanks. I created the RTB dynamically and was able to format the text as required by using the code sample you provided in the first answer combined with the last.
0
All Courses

From novice to tech pro — start learning today.