Recent

Author Topic: TRadioGroup font does not accept chosen color  (Read 3299 times)

TeoUrbana

  • New Member
  • *
  • Posts: 43
    • Distração For Fun
TRadioGroup font does not accept chosen color
« on: May 15, 2020, 10:42:17 pm »
When choosing a color for the RadioGroup font, he does not accept it. The font is always black.

I need a solution that is not to uncheck the option "Use Manifest resource ..." in Project -> Project Options, because unchecking this option solves the font color problem, but it spoils something else.

I tried the following:
Code: Pascal  [Select][+][-]
  1. TControl (RadioGroup1) .Font.Color: = clRed;
But nothing done.

Does anyone have a solution that works?

(translated from portuguese to english by google)  8)

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TRadioGroup font does not accept chosen color
« Reply #1 on: May 15, 2020, 10:44:03 pm »
You are on Windows obviously.. Its controlled by the OS GUI..

 Other Widgets can change their color..

 I am not sure if that control has a ownerDraw option in it, it should have If not..
The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TRadioGroup font does not accept chosen color
« Reply #2 on: May 15, 2020, 10:54:29 pm »
Hi!

No - TRadiogroup has no OwnerDraw option.

So: Windows is too dump for TRadiogroup.Font.Color.

Write a letter to Bill Gates.

Winni

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TRadioGroup font does not accept chosen color
« Reply #3 on: May 16, 2020, 01:05:06 am »
actually you can color the boxes but it involves hooking into the window procedure to catch the WM_PAINT , etc...
The only true wisdom is knowing you know nothing

TeoUrbana

  • New Member
  • *
  • Posts: 43
    • Distração For Fun
Re: TRadioGroup font does not accept chosen color
« Reply #4 on: May 16, 2020, 05:59:23 pm »
See the first image:
"Use manifest feature (and enable themes)", which is under Project -> Project Options, is disabled.
  • The RadioGroup font = Green (As I want)
  • RadioGroup1.ParentColor property = false
The RadioGroup's background is yellow (it's the color of the form). Where's the transparency?  >:(

In the second image, I enabled the option "Use manifest resource (and enable themes)"
  • Problem transparency: Solved
  • Font color: not green.

I think the key is to understand how the Use manifest feature option works, and to use this code to change the font color, but unfortunately for me, this is a distant knowledge from my current level (I'm still fighting with the OOP).

Can anyone get around this situation?  :'(

In the case of Windows, the ideal is to leave the "use manifest feature ..." checked, because the images on disabled buttons, the font design, etc ... the images get better.
« Last Edit: May 16, 2020, 06:21:13 pm by TeoUrbana »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TRadioGroup font does not accept chosen color
« Reply #5 on: May 16, 2020, 06:18:41 pm »
Note the second part of that option:
  • "Use manifest feature (and enable themes)"
With themes enabled, the Windows theming engine takes almost absolute control of all the drawing, bypassing (and ignoring) most any "custom" options you might set: font, colors, etc.

There is little the LCL can do to avoid it since that behaviour is set on stone by Windows itself. And not only Windows: it might happen also on other widgetsets, depending on several conditions.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

TeoUrbana

  • New Member
  • *
  • Posts: 43
    • Distração For Fun
Re: TRadioGroup font does not accept chosen color
« Reply #6 on: May 16, 2020, 07:33:34 pm »
Quote
... that behaviour is set on stone by Windows itself.

But, is there not a way to overload?

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: TRadioGroup font does not accept chosen color
« Reply #7 on: May 16, 2020, 10:38:33 pm »
Quote
... that behaviour is set on stone by Windows itself.
But, is there not a way to overload?
Whether it is necessary? By changing the standard behavior and appearance of controls, we make the interface less familiar, i.e. degrades usability.
Only at first the unusual can attract attention. Later the functionality and speed of control come first, and then the standardness of the interface becomes more important.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TRadioGroup font does not accept chosen color
« Reply #8 on: May 17, 2020, 12:47:31 am »
I absolutely agree with ASerge that it is not a good idea to change colors of a themed user interface at will. But maybe you have good reason for it. So, for this case, here is a "faked radiogroup" in which you can change the colors of the buttons arbitrarily:
  • Use a TGroupbox and add as many RadioButtons as you will need
  • Delete the captions of each RadioButton
  • Add a Label component for each RadioButton. Enter here the caption that would normally be with the RadioButton.
  • Set the Font color of the Labels as needed.
  • To avoid seeing a small dotted focus rectangle around the empty Radiobutton caption you should top-align each radiobutton; use BorderSpacing settings for appropriate margins
  • Now use the AnchorEditor the align each label vertically to the center of its RadioButton.
Almost perfect...

When you select items with the keyboard you will notice a slight difference to a "true" RadioGroup: While you can navigate with the UP/DOWN arrows in the RadioGroup and select the radio items simultaneously you only navigate in the faked group and must press the space bar to select the item. There is no difference when you select items with the mouse.

A large difference, however, exists in source code: you no longer have the Items[] and ItemIndex properties. Now you must query the Checked property of the individual radiobuttons.

I tested this on Windows, and it works fine - see screenshot. But I could imagine that there are other widgetsets which do not allow to modify the font color of a Label. In this case you could try a TStaticText, or you could draw the item captions directly on the canvas, without using a component. But in the latter case, the entire business gets more complex because the Groupbox does not expose an OnPaint event - probably it would be easier to create a small component based on this idea.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TRadioGroup font does not accept chosen color
« Reply #9 on: May 17, 2020, 01:04:17 am »
Hi!

I found in my sources a quick hack from Delphi1 times.

The details must be inserted by you.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var s : string;
  3. can : TCanvas;
  4.  
  5. begin
  6. Can := TCanvas.Create;
  7. Can.Handle := GetDC(RadioGroup1.handle);
  8. can.Brush.color := clAqua;
  9. can.Font.Color := clRed;
  10. s := RadioGroup1.Items[0];
  11. RadioGroup1.Items[0] := '';
  12. Application.ProcessMessages;
  13. can.FillRect(30,10,60,35);
  14. can.TextOut (30,10,s);
  15. ReleaseDC(RadioGroup1.handle, Can.Handle);
  16. Can.Free;                          
  17. end;

Winni

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TRadioGroup font does not accept chosen color
« Reply #10 on: May 18, 2020, 12:44:20 pm »
Another less hacky solution: Install package pl_exControls from the Online Package Manager. It contains a TplRadioButton (and a TplCheckbox) which descends directly from TCustomControl, not from TCustomRadioButton; therefore, you have more control of its properties than with the standard TRadioButton. In particular, you can change the font color as you request.

Put several of these plRadioButtons into a TGroupbox, and you'll have something close to a RadioGroup with color items.
« Last Edit: May 18, 2020, 01:21:44 pm by wp »

TeoUrbana

  • New Member
  • *
  • Posts: 43
    • Distração For Fun
Re: TRadioGroup font does not accept chosen color
« Reply #11 on: May 19, 2020, 02:17:13 am »
Quote
I absolutely agree with ASerge that it is not a good idea to change colors of a themed user interface at will.

It is a matter of visual identity. My taste is not very good, but I am trying something different.

winni, thanks for the suggestion. It was almost good. But the background has to be transparent, because of the background colors.

wp, thanks for the pl_exControls suggestion, but it also has a transparency problem and is little ugly.

The way will be to put several GroupBox, RadioButton and Labels, to achieve the desired effect.
It will take work but do what? Is life.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TRadioGroup font does not accept chosen color
« Reply #12 on: May 19, 2020, 09:50:20 am »
wp, thanks for the pl_exControls suggestion, but it also has a transparency problem
In fact, and it also does not handle LCL scaling.

In the meantime I've been working on my own set of custom-drawn check controls (TRadioButtonEx, TCheckBoxEx) and their grouped versions (TRadioGroupEx, TCheckGroupEx). Their code is a combination (and extension) of TCheckboxThemed and TRadioGroup/TCheckGroup. They will respect the Font settings and provide some more properties like vertical alignment, multiple lines and user-defined bitmaps for check marks. Just give me some time to complete.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TRadioGroup font does not accept chosen color
« Reply #13 on: May 22, 2020, 10:32:02 am »
Done. Please see my post at https://forum.lazarus.freepascal.org/index.php/topic,46141.msg363193.html#msg363193 (I don't want to double-post).

TeoUrbana

  • New Member
  • *
  • Posts: 43
    • Distração For Fun
Re: TRadioGroup font does not accept chosen color
« Reply #14 on: May 25, 2020, 10:01:36 pm »
wp,
thanks for the components. They will supply the need for several developers who face this problem (in this forum we have several posts on the subject).

Without wanting to abuse ... but already abusing  :), could you extend the functionality of the font color of the buttons, to the caption of RadioGroup too?

 

TinyPortal © 2005-2018