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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.