Click here to Skip to main content
16,016,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i'm trying to figure it out how to set in CStatic control text and some text should be with one font and some text should be with another font. How can i do it?
Thanks in advance!
Posted

To do this, you need to subclass CStatic control, then you can change whole drawing behavior as you need by handling WM_PAINT message (OnPaint() in MFC). I'm sure you can find lots of example in this site. If you can't find, I can help further.
 
Share this answer
 
Comments
George Findulov 10-Mar-11 16:51pm    
Thanks for the reply, i will check your solution to see if it works.
I would only recommend overwriting OnPaint() if there's big changes, its not worth creating a class just to change the font.

Here's a couple of better ways (rather than overwriting the OnPaint() just to change the font):
http://www.codeproject.com/Messages/3064309/Control-CStatic-Height-of-FONT.aspx[^]
http://www.dotnetheaven.com/Uploadfile/mahesh/font04272005052608AM/font.aspx[^]
 
Share this answer
 
Comments
Ozer Karaagac 10-Mar-11 17:35pm    
OK, but, OP would like to have "some text should be with one font and some text should be with another font". At least two different fonts. Is it possible with SetFont() or WM_SETFONT?
Albert Holguin 10-Mar-11 18:48pm    
Well, it really depends on what he's trying to do... For example, if he's using one font for a label and one font for body text, you can achieve the desired effect with two CStatic objects each with its own font. If he HAS to have both in the same static, then I would have to agree with you, would probably have to overwrite OnPaint() at that point. Can probably make for an interesting project if you make the new CStatic derived class be markup controlled (wonder if anyone's done that already? prob something can be derived with html classes...).
Ozer Karaagac 10-Mar-11 19:52pm    
Yes, two static controls can be an option. But, much more controls means more resource consumption and may be performance penalty. Subclassing a control for such a specific function is not so tedious especially while using MFC and it can be used across all projects. I'll consider your project suggestion (if I have time). :-)
Albert Holguin 10-Mar-11 20:02pm    
time is never on our side! :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900