1

I would like to be able to apply a certain style to a handful of BitBtn in an application I am working on. I have applied a VCL style to skin my whole application.

From what I understood in reading on the web, I could define my own child class of the TBitBtn and then I could define a style hook for that given class.

I had it work with TLabel and TEdit, but I am not quite sure how to manage it for TButton or TBitBtn. Essentially, I'd like to apply a different background image to the custom TBitBtn rather than the one included in the theme.

LU RD
  • 34,438
  • 5
  • 88
  • 296
Alexandre
  • 507
  • 1
  • 5
  • 16
  • Can you give an example of what you want? Either use the code that you already have for the TEdit, or some pseudo-code that would explain what you'd want to do with the TButton. – Johan Oct 02 '13 at 16:12

1 Answers1

4

To modify the appearance of a TBitBtn using the Vcl Styles, depends of your Delphi version

XE4, XE5

you must create a new style hook derived from the TBitBtnStyleHook class and then override the DrawButton method. Check this question Disabling TButton issue on a VCL styled form where I post a sample code that override the TButtonStyleHook.Paint method in this case to fix a bug, but you can adapt the same code for your own needs.

XE2, XE3

The TBitBtn doesn't uses style hook on these versions , so your only option is handle the CN_DRAWITEM message for the TBitBtncontrol and then add your own code to draw the button like is explained in this answer Delphi XE2 VCL styles, How to disable VCL styles on TBitBtn?

Community
  • 1
  • 1
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • It tried TStyleManager.Engine.RegisterStyleHook(TBitBtn, TButtonStyleHookFix); but it does not seem to call my hook on the TBitBtn I have in my form. TStyleManager.Engine.RegisterStyleHook(TButton, TButtonStyleHookFix); works for buttons thoug. Are TBitBtns using the TButtonStyleHook as well or something else? – Alexandre Oct 02 '13 at 17:24
  • in http://stackoverflow.com/questions/12195687/delphi-xe2-vcl-styles-how-to-disable-vcl-styles-on-tbitbtn you claim that there is no hook for the TBitBtn – Alexandre Oct 02 '13 at 17:30
  • @Alexandre, sorry but I missed you Delphi Version, in the newest versions of Delphi the `TBitBtn` uses a Style Hook (TBitBtnStyleHook), answer updated. – RRUZ Oct 02 '13 at 18:09