Delphi XE2 VCL样式,如何在TBitBtn上禁用VCL样式? [英] Delphi XE2 VCL styles, How to disable VCL styles on TBitBtn?

查看:107
本文介绍了Delphi XE2 VCL样式,如何在TBitBtn上禁用VCL样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Delphi XE2中使用了新的VCL样式系统,它的工作正常,但是在一种形式上我想例外.此表单包含多个TBitBtn控件,每个TBitBtn控件都有自己的字体颜色(clRed,clBlue,clLime等),与其他字体颜色不同. 由于实施了样式,所有TBitBtn控件的标题都以黑色显示,而不是设置颜色. 是否有任何TStyleHook可以在TBitBtn控件上注册,从而在该窗体上禁用了TBitBtn控件上的样式?

I am using the new VCL styles system in Delphi XE2 and its work fine but on one Form I want exception. This Form contains number of TBitBtn control and each TBitBtn control has its own Font colour (clRed, clBlue, clLime etc) different from other. Due to Style implementation all TBitBtn control’s Caption is display in black colour instead of set colour. Is there any TStyleHook, which can be register on TBitBtn control, which disabled the Style on TBitBtn Control on that form?

推荐答案

TBitBtn 组件不使用vcl样式钩子,此控件使用TButtonGlyph类(在Vcl.Buttons单元的实现部分中定义和实现)来使用Windows主题绘制按钮或当前的vcl样式,此类(TButtonGlyph)在该单元之外无法访问,因此您不走运.

The TBitBtn component doesn't use a vcl style hook, this control use the TButtonGlyph class (which is defined and implemented in the implementation part of the Vcl.Buttons unit) to draw the button using the Windows theme or the current vcl style, this class (TButtonGlyph) is not accessible outside of this unit , so you are out of luck here.

我想到的唯一选择是创建一个插入器类,并拦截TBitBtn控件的CN_DRAWITEM消息,然后执行您自己的代码以绘制按钮.

The only option which comes to my mind is create a interposer class and intercept the CN_DRAWITEM message for the TBitBtn control and then execute your own code to draw the button.

  TBitBtn = class(Vcl.Buttons.TBitBtn)
  private
   procedure MyDrawItem(const DrawItemStruct: TDrawItemStruct);
  public
   procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
  end;

procedure TBitBtn.CNDrawItem(var Message: TWMDrawItem);
begin
  MyDrawItem(Message.DrawItemStruct^);
end;

procedure TBitBtn.MyDrawItem(const DrawItemStruct: TDrawItemStruct);
begin
  //the new code goes here.
end;

这篇关于Delphi XE2 VCL样式,如何在TBitBtn上禁用VCL样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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