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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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)
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;