Solved

Using fonts etc

Posted on 2003-11-02
7
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9666422
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
ID: 9676377
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
ID: 9677932
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ragin_cajun
ID: 9679035
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
ID: 9679502
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
ID: 9681694
No that should be all you need to do, if you have questions post them.
0
 

Author Comment

by:Maritimer
ID: 9683810
Thanks again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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