How do you change the text color of a CStatic text control? Is there a simple way other that using the CDC::SetTextColor?
thanks...
How do you change the text color of a CStatic text control? Is there a simple way other that using the CDC::SetTextColor?
thanks...
unfortunately you won't find a SetTextColor method in the CStatic class. If you want to change the text color of a CStatic you will have to code a bit more.
In my opinion the best way is creating your own CStatic-derived class (CMyStatic) and there cacth the ON_WM_CTLCOLOR_REFLECT notification message.
Obviously you can use a member variable and a setter method to replace the red color (RGB(255,0,0)).
Regards.
You can implement
ON_WM_CTLCOLOR
in your dialog class, without having to create a new CStatic-derived class:Notice that the code above sets the text of all static controls in the dialog. But you can use the
pWnd
variable to filter the controls you want.From the Answers given here and other places, it was not obvious how to create a derived class to be used instead of CStatic that handles coloring itself.
So following is what works for me, using MSVS 2013 Version 12.0.40629.00 Update 5. I can place a "Static Text"-control in the resource editor, then replace the type of the member variable with TColorText.
In the .h-file:
in the .cpp-file:
Very helpful.
https://msdn.microsoft.com/de-de/library/0wwk06hc.aspx
Alike to
Just a follow up to the painting issue (a transparent background), which caused by *return (HBRUSH)GetStockObject(NULL_BRUSH);*
Easy change as below:
Hope this helps.