Solved

Using fonts etc

Posted on 2003-11-02
7
384 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 55
not able to insert into temp table 68 157
Line meaning 9 82
Fibonacci challenge 11 110
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now