Delphi XE2使用VCL Styles (皮肤/skin)

在新版本中,你可以直接给你的程序换皮肤/skin(主题),Project-> Options -> Application -> Appearance,在这里选一个你想要的主题,



当然,你可以在你的程序里自己设定,为了使用VCL Styles,你需要使用TStyleManager类,Themes单元,如下几步:
注册Style
从文件加载(注册)VCL style,需要使用TStyleManager类中的LoadFromFile函数,

复制代码

  1. procedure RegisterStyleFromDisk(const StyleFileName: string);
  2. begin
  3.   try
  4.     if TStyleManager.IsValidStyle(StyleFileName) then
  5.     TStyleManager.LoadFromFile(StyleFileName);
  6.     //beware in this line you are only loading and registering a VCL Style and not setting as the   current style.
  7.   else
  8.     ShowMessage('the Style is not valid');
  9. end;


然后使用LoadFromResource或TryLoadFromResource从源加载style

复制代码

  1. procedure RegisterStyleFromResource(const StyleResource: string);
  2. begin
  3.   TStyleManager.LoadFromResource(HInstance, StyleResource);
  4.   //beware in this line you are only loading and registering a VCL Style and not setting as the current style.
  5. end;


设置Style
设置已经加载好的Style,需要使用SetStyle(或TrySetStyle) procedure.
注意:SetStyle 有3个重载版本

复制代码

  1. //class procedure SetStyle(const Name: string); overload;
  2.     TStyleManager.SetStyle('StyleName');

复制代码

  1. //class procedure SetStyle(Style: TCustomStyleServices); overload;
  2.     TStyleManager.SetStyle(TStyleManager.Style['StyleName']);

复制代码

  1. //class procedure SetStyle(Handle: TStyleServicesHandle); overload;
  2.     TStyleManager.SetStyle(TStyleManager.LoadFromFile(StyleFileName))


使用上面代码写的Demo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蝈蝈(GuoGuo)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值