[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Using fonts etc

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
Maritimer
Asked:
Maritimer
  • 3
  • 3
1 Solution
 
Roshan DavisCommented:
Try this link
http://www.codeproject.com/staticctrl/xhtmlstatic.asp - XHTMLStatic - An extra-lean custom control to display HTML

Good luck
0
 
ragin_cajunCommented:
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
 
MaritimerAuthor Commented:
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!

 
ragin_cajunCommented:
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
 
MaritimerAuthor Commented:
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
 
ragin_cajunCommented:
No that should be all you need to do, if you have questions post them.
0
 
MaritimerAuthor Commented:
Thanks again
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now