The background color of a TButton is controlled by Windows, not Delphi. TButton is a simple wrapper around the standard Windows button, and Windows does not allow it to be colored except by choosing the colors in Control Panel.
TButton的背景色由Windows控制,而不是由Delphi控制。 TButton是标准Windows按钮的简单包装,Windows不允许对其着色,除非在“控制面板”中选择颜色。
This means you can not set the background color of a TButton, nor you can change the background color of TBitBtn or TSpeedButton.
这意味着您不能设置TButton的背景色,也不能更改TBitBtn或TSpeedButton的背景色。
Since Windows insists on doing the background coloring with clBtnFace, the only way to change it is to draw the button yourself by making an owner-drawn button component.
由于Windows坚持使用clBtnFace进行背景着色,因此更改它的唯一方法是通过制作所有者绘制的按钮组件自己绘制按钮。
TColorButton源代码 ( TColorButton Source Code )
The TColorButton adds three new properties to the standard TButton:
TColorButton在标准TButton中添加了三个新属性:
BackColor - Specifies the background color of the button
BackColor-指定按钮的背景色
ForeColor - Specifies the color of the button text. Note that this "overrides" the Font.Color property
ForeColor-指定按钮文本的颜色。 请注意,这“覆盖”了Font.Color属性。
HoverColor - Specifies the color used to paint the button's background when the mouse hovers over the button.
HoverColor-指定当鼠标悬停在按钮上时用于绘制按钮背景的颜色。
Here's how to set color-related properties of the TColorButton at runtime:
这是在运行时设置TColorButton的颜色相关属性的方法:
ColorButton1.BackColor := clOlive; //background
ColorButton1.ForeColor := clYelow; //text
ColorButton1.HoverColor := clNavy; //mouse over
安装到组件面板 ( Installing Into a Component Palette )
The TColorButton comes as a single unit file with the .PAS file extension. After downloading the component, you need to install the source component into an existing package.
TColorButton是带有.PAS文件扩展名的单个单元文件。 下载组件后,需要将源组件安装到现有软件包中。
翻译自: https://www.thoughtco.com/source-code-for-tcolorbutton-4077901