1
votes

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
Why you are using a TBitBtn instead of a TButton? I ask because the TButton uses a Vcl style hook and can be customizable easily.RRUZ
We recently migrated our application from Delphi 4 to Delphi XE2. This TBitBtn button functionality was introduce decade ago and we don't why it was used that time. It is always risky to change a working code so I am little sceptical to change control without giving through thought. If we find a workable solution without too much code change than it is good else have to think differently and introduce new component as you suggested which will required more testing and effort.Sanjay Gajbhiye

1 Answers

2
votes

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;