具有颜色属性的TColorButton

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值