我知道可以禁用组件的自定义样式,但是如何仅启用一个组件类的样式?比如只保留整个表单和其中所有组件的默认样式,而仅对TButton进行美化。就像这张图片上所示。
我知道可以禁用组件的自定义样式,但是如何仅启用一个组件类的样式?比如只保留整个表单和其中所有组件的默认样式,而仅对TButton进行美化。就像这张图片上所示。
StyleServices
全局函数来获取绘制控件的方法。因此,如果您不使用Vcl样式,则StyleServices
返回一个实例,该实例使用Windows API函数来绘制主题化控件(UxTheme API)。因为没有办法只为单个类控件(至少是您自己绘制的控件)应用Vcl样式。procedure DisableVclStyles(Control : TControl;const ClassToIgnore:string);
var
i : Integer;
begin
if Control=nil then
Exit;
if not Control.ClassNameIs(ClassToIgnore) then
Control.StyleElements:=[];
if Control is TWinControl then
for i := 0 to TWinControl(Control).ControlCount-1 do
DisableVclStyles(TWinControl(Control).Controls[i], ClassToIgnore);
end;
使用 Vcl 样式检查此表单
现在调用上述方法后
DisableVclStyles(Self,'TButton');
注意:使用 StyleElements 属性来启用或禁用 VCL 样式,无法与某些组件(如 TStringGrid、TBitBtn、TSpeedButton 等)一起工作。
TControl
没有StyleElements
属性。 - Jerry Dodge
TButton
组件的子类,它看起来不像通常的TButton
。 将 VCL 样式功能添加到项目中,然后对整个项目进行禁用(除了TButton
),这不是在项目中仅为一个按钮换肤的好方法。 - teran