DELPHI - How to change a TButton background color in a VCL Form Application?
12,616
Solution 1
You can't change the color of a TButton
component directly, instead you must use a third-party component or owner draw the button (BS_OWNERDRAW
).
Solution 2
- Create a panel.
- Change panel's color to any color.
- Empty panel's caption.
- Create a SpeedButton inside the panel.
- Set SpeedButton's Flat property True.
- Set SpeedButton's Align propert alClient.
- Voila! Here is your button with color!
Original source: https://engineertips.wordpress.com/2020/07/21/delphi-button-background-color/
Author by
stacker
Updated on June 05, 2022Comments
-
stacker almost 2 years
In my Delphi VCL Form Application I have to change the background color of a TButton. Is there a way to apply this change without using a third-party components?
Thanks.
-
stacker about 11 yearsHow can I implement the drawing of the Button?
-
David Heffernan about 11 yearsThe link in the answer covers that. You'll need to respond to
WM_DRAWITEM
. -
sevenOfNine almost 3 years10.2 Tokyo. This works only in the design mode. When I try this in source code, the color goes away.