Change TToolBar background color
Asked Answered
P

1

6

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
Potboiler answered 6/9, 2016 at 9:21 Comment(6)
Is ParentColor false?Electrotype
@LURD Sure, it sets automaticly to False when u change Color property.Potboiler
Themed controls are, well, themed. You don't get to determine their colours. The theme does. If you don't like that, disable themes.Hennessey
@LURD, ParentColor does not work on a TToolBar. The only reason it seems to work is because Transparent = true by default.Pate
@DavidHeffernan Themed doesn't mean, that you can't change its appearance at all, because there is always some workaround. I just don't understand purpose of Color property, if its useless, even if documentation says something different.Potboiler
Nope. It's exactly as I said.Hennessey
P
12

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.

Pate answered 6/9, 2016 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.