CJC Delphi 技巧馆's Archiver

cjc Posted at 2013-7-12 15:35

Delphi XE2 VCL styles, How to disable VCL styles on TBitBtn?

Delphi XE2 VCL styles, How to disable VCL styles on 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?


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.

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)
   procedure MyDrawItem(const DrawItemStruct: TDrawItemStruct);
   procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;

procedure TBitBtn.CNDrawItem(var Message: TWMDrawItem);

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

Page: [1]
CJC好玩背单词最新版本 - 是目前最好的背单词软件,游戏好玩,功能强大,词库众多,还有真人语音,免费下载,免费试用 !

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.