Solved

Using fonts etc

Posted on 2003-11-02
7
382 Views
Last Modified: 2013-12-03
I have some text being displayed on my form. How do I chnge the fonts for specifics words such as color, Bold, underline, font type etc.

example

m_string = "This is a TEST";

I would like the TEST to be underlined and set to a larger font etc, maybe new color.

Regards,
0
Comment
Question by:Maritimer
  • 3
  • 3
7 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Try this link
http://www.codeproject.com/staticctrl/xhtmlstatic.asp - XHTMLStatic - An extra-lean custom control to display HTML

Good luck
0
 
LVL 1

Expert Comment

by:ragin_cajun
Comment Utility
Is the text on your form static text controls or are you outputting it with the GDI functions like TextOut / DrawText ? There's a different method for altering the font with those 2 - please post I'll give you some examples.
0
 

Author Comment

by:Maritimer
Comment Utility
I am using the static text control. I have looked through my books and have not bee able to find anything.
Due to the nature of this application I cannot import any custom controls outside of the functions Microsoft provides.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:ragin_cajun
Comment Utility
Ok static text control - I had the same problem you did. Changing the color of the font involves one function, the font, another. You don't have to import any custom controls just do it like this:

For color:

You'll have to add the OnCtlColor message handler to your dialog. You can do this by selecting your dialog in the resource editor and from the message list add OnCtlColor. It'll automatically generate the frame for the function like so:

HBRUSH CWhateverDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
               HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);                        

               // Here is what you'll add to change the color
               if (pWnd->GetDlgCtrlID() == IDC_MY_STATICTEXT_ID)
               {
                                // Now you've intercepted the correct static text control
                                // now make a colorref and set it to that color
                                COLORREF blue = RGB (0, 0, 255); // pure blue
                                pDC->SetTextColor(blue);
                                // this sets the background color of your text appropriately - I think you
                                // can use TRANSPARENT as well.
                                COLORREF bg =  GetSysColor( COLOR_3DFACE );
                                pDC->SetBkColor( bg );
                  
                                hbr = m_brush;
                }

                return hbr;
}

Declare your brush in your dialog class as:
CBrush m_brush;

And on InitDialog or wherever you like initialize its color like this:
//sets the color of this brush to the sys bg color
m_brush.CreateSolidBrush(GetSysColor(COLOR_3DFACE));



For font:

Pretty easy, you can use the SetFont function.

First create a font, look up LOGFONT on msdn.com.
The parameters for the font will include all that you are wondering about such as size, underline, strikethrough, type face, etc.

Once you have your font defined, you can simply create a control variable for the static text contol, then use:

my_statictext_control.SetFont(FontName, Redraw(t/f));

Then it will be drawn in the font you defined.

Goodluck, feel free to post any questions.
0
 

Author Comment

by:Maritimer
Comment Utility
Thanks excellent answer.

I dont have time to try it today they have me do a quick litttle assignement.

However I understand the code. Is there anything else I should be aware of.

0
 
LVL 1

Accepted Solution

by:
ragin_cajun earned 50 total points
Comment Utility
No that should be all you need to do, if you have questions post them.
0
 

Author Comment

by:Maritimer
Comment Utility
Thanks again
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
Fibonacci challenge 11 81
wordappend challenge 8 83
Making an alias 7 51
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now