Reputation: 45243
I want to modernize an old VCL application based on a design template. That design template contains different button styles. Let's say there are three types of buttons: LightButton
, DarkButton
and GreenButton
.
Since more than 50% of all buttons will appear as DarkButton
I modified the appearance of TButton
to the dark design using the Bitmap Style Designer.
Now I want to add the other button styles to the .vsf
file and use it in my application. What is the best way to do it?
Do I need to create new button classes and new descendants of TStyleHook
which paint entirely new buttons? If yes, is there a way to reuse as much code as possbile from Vcl.StdCtrls.TButtonStyleHook
?
Are there any other approaches, best practices or examples?
Upvotes: 0
Views: 1026
Reputation: 136411
Q : Now I want to add the other button styles to the .vsf file and use it in my application. What is the best way to do it?
A : The VCL Styles internals doesn't allow to use more than one button style from the vsf file. (The images inside of the VCL Styles files are used to mimic and replace the Windows Themes states and parts).
Q : Do I need to create new button classes and new descendants of TStyleHook which paint entirely new buttons?
A : Yes that is the way, you must create a new styleHook to paint the buttons your self.
Q : Is there a way to reuse as much code as possible from Vcl.StdCtrls.TButtonStyleHook?
A : Yes, You only need to inherit your style hook from the TButtonStyleHook
class and then override the Paint
method.
TNewButtonStyleHook = class(TButtonStyleHook)
protected
procedure Paint(Canvas: TCanvas); override;
end;
Q : Are there any other approaches, best practices or examples?
A : Try these samples of custom TButton Style Hooks.
Upvotes: 5