Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change TToolBar background color

I got a problem, that I can't normally change the background color (e.g. clwhite) of TToolBar with its property ToolBar.Color. I'm not very experienced in Delphi and I find out two possible solutions, but still I'd like to know, how to change it proper way or why it's not possible.

1) Change style to Gradient, but it also changes the basic animations for buttons.

ToolBar.DrawingStyle := dsGradient
ToolBar.GradientStartColor := clWhite
ToolBar.GradientEndColor := clWhite

2) Put TToolBar inside TPanel with the following settings.

Panel.Color := clwhite
ToolBar.Parent := Panel
ToolBar.Align := alClient
ToolBar.Transparent := True
like image 272
Triber Avatar asked Sep 06 '16 09:09

Triber


1 Answers

By default a TToolbar ignores its Color property.
Also by default the Transparent property is true, therefore whatever the color of the Toolbar's parent is will shine through.

If you look at the VCL source code you'll see that TToolbar does not do its own drawing; it is a wrapper around the ToolbarWindow32 Win32 common control in ComCtl32.dll.
This is the code that does the drawing.
When Windows XP was introduced Microsoft added UI themes and Borland supported this via VCL.Themes.TStyleManager.
You can change the appearance of Common Controls through the style manager: Project -> Options -> Appearance -> Custom Styles, but its hard to know what effect this has, because the IDE does not display the result (you can see it at run time) and you can only choose from a limited list of rather odd themes; also the feature is buggy.

The same goes for TPageControl/TTabSheet which does not publish its Color propery.
All the controls imported via ComCtl32.dll and implemented by VCL.ComCtrls suffer from these inconsistencies.

In short
There is nothing you can do to make TToolbar respect its Color property.
You've already found the workarounds, either:

  1. Set a gradient with identical GradientEndColor and GradientStartColor, or

  2. Place the toolbar on another control (e.g. a TPanel) and change the color of that control, because the toolbar is transparent the parent color will shine through.
    You'll need to set the panel's BevelInner/BevelOuter to bvNone, or

  3. Enable VCL styles and suffer all the issues related with that corporate tickbox anti-pattern.

like image 61
Johan Avatar answered Nov 15 '22 05:11

Johan