简体   繁体   English

更改TToolBar背景颜色

[英]Change TToolBar background color

I got a problem, that I can't normally change the background color (eg clwhite ) of TToolBar with its property ToolBar.Color . 我遇到了一个问题,我通常TToolBar使用其属性ToolBar.Color更改clwhite的背景颜色(例如clwhite )。 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. 我在Delphi方面不是很有经验,我找到了两种可能的解决方案,但我仍然想知道,如何正确地改变它或为什么它不可能。

1) Change style to Gradient, but it also changes the basic animations for buttons. 1)将样式更改为渐变,但它也会更改按钮的基本动画。

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

2) Put TToolBar inside TPanel with the following settings. 2)使用以下设置将TToolBar放入TPanel中。

Panel.Color := clwhite
ToolBar.Parent := Panel
ToolBar.Align := alClient
ToolBar.Transparent := True

By default a TToolbar ignores its Color property. 默认情况下, TToolbar忽略其Color属性。
Also by default the Transparent property is true , therefore whatever the color of the Toolbar's parent is will shine through. 默认情况下, Transparent属性为true ,因此无论工具栏的父级颜色是什么,都会闪耀。

If you look at the VCL source code you'll see that TToolbar does not do its own drawing; 如果您查看VCL源代码,您会看到TToolbar没有自己的绘图; it is a wrapper around the ToolbarWindow32 Win32 common control in ComCtl32.dll . 它是围绕着一个包装ToolbarWindow32在Win32中常见的控制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 . 当Windows XP被引入时,Microsoft添加了UI主题,Borland通过VCL.Themes.TStyleManager支持了这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; 您可以通过样式管理器更改公共控件的外观: Project -> Options -> Appearance -> Custom Styles ,但很难知道它有什么影响,因为IDE不显示结果(您可以在运行时看到它)时间)你只能从有限的奇怪主题列表中选择; also the feature is buggy. 这个功能也是错误的。

The same goes for TPageControl/TTabSheet which does not publish its Color propery. TPageControl/TTabSheet ,它不会发布其Color propery。
All the controls imported via ComCtl32.dll and implemented by VCL.ComCtrls suffer from these inconsistencies. 通过ComCtl32.dll导入并由VCL.ComCtrls实现的所有控件VCL.ComCtrls受到这些不一致的影响。

In short 简而言之
There is nothing you can do to make TToolbar respect its Color property. 没有什么可以让TToolbar尊重它的Color属性。
You've already found the workarounds: 您已经找到了解决方法:

  1. Set a gradient with identical GradientEndColor and GradientStartColor . 设置具有相同GradientEndColorGradientStartColor

  2. Place the toolbar on another control (eg a TPanel) and change the color of that control, because the toolbar is transparent the parent color will shine through. 将工具栏放在另一个控件(例如TPanel)上并更改该控件的颜色,因为工具栏是透明的,父颜色将透过。
    You'll need to set the panel's BevelInner / BevelOuter to bvNone . 您需要将面板的BevelInner / BevelOuterbvNone

  3. Enable VCL styles and suffer all the issues related with that corporate tickbox anti-pattern. 启用VCL样式并遇到与该公司复选框反模式相关的所有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM