Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change caption font color on TCheckBox, TRadioButton, TGroupBox?

I don't know what my problem is, but I cannot set the font color in DEx2 for controls like TCheckBox, TRadioButton, TGroubBox, and TRadioGroup. It doesn't matter if I do it in the IDE or programmatically.

I have set my form color to clBlack and want my captions to be clWhite, but they won't render any color but clBlack. When I assign a color on a form's OnShow event and step through it in the debugger, it shows the value I assigned it, but on the screen it is still black.

I am not using styles or anything else. Any ideas?

Here is a sample form: white on black example http://www.skippix.us/temp/Delphi-Font-Problem.bmp

like image 411
skippix Avatar asked Sep 03 '12 13:09

skippix


2 Answers

When you uses the windows themes in an application, most of the custom settings like the font colors are ignored. As workaround and depending of the component you can ownerdraw the control (only when this feature is supported), override the paint method in order to use your own color in the font (TRadioGroup, TGroupBox), and for components like TCheckBox and TRadioButton (which are WinAPI controls wrappers) you must intercept the WM_PAINT windows message and implement your own code to draw the control.

Also starting with Delphi-xe2 you can use the vcl styles which allow you to change the appearance of the controls, from here (and when is possible) you can modify the style hooks to apply your own font colors and other customizations.

like image 137
RRUZ Avatar answered Oct 31 '22 15:10

RRUZ


A simple and easier workaround is to create a checkbox without caption and add a label after it. You can easily change the label's color. You can also create a new component that binds a label to the checkbox itself. That's what worked for me on Delphi 2007.

like image 3
delphirules Avatar answered Oct 31 '22 17:10

delphirules