在Delphi中只调用一个VCL组件 [英] Styling only one VCL component in Delphi

查看:186
本文介绍了在Delphi中只调用一个VCL组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,可以禁用组件的自定义样式,但是如何只为一个组件类启用样式?例如,将整个表格和所有组件放在它上面,不要使用皮肤,只能使用TButton。喜欢这张照片。



解决方案

大多数VCL控件内部使用 属性以启用o禁用vcl样式不适用于某些组件(如TStringGrid,TBitBtn,TSpeedButton等) )


I know, that it's possible to disable custom styling for components, but how can I enable styles for only one component class? For example leave the whole form and all components on it unskinned, and skin only TButton. Like on this image.

解决方案

Most of the VCL controls internally uses the StyleServices global function to get the methods to draw the control. So if you are not using the Vcl Styles, the StyleServices return an instance to the windows API functions to draw themed controls (UxTheme API's). because that there is not way to skin (apply the Vcl Styles) to only a single class control (at least which you draw the control yourself).

So the only alternative is apply a Vcl Styles and then disable for all the controls except the one type which you are looking for.

You can use something like this

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;

Check this form with a Vcl Style

And now after of call the above method

DisableVclStyles(Self,'TButton');

Note : using the StyleElements property to enable o disable the vcl styles doesn't work with some component like (TStringGrid, TBitBtn, TSpeedButton and so on)

这篇关于在Delphi中只调用一个VCL组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆