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

  1. Create a panel.
  2. Change panel's color to any color.
  3. Empty panel's caption.
  4. Create a SpeedButton inside the panel.
  5. Set SpeedButton's Flat property True.
  6. Set SpeedButton's Align propert alClient.
  7. Voila! Here is your button with color!

Original source: https://engineertips.wordpress.com/2020/07/21/delphi-button-background-color/

Share:
12,616
stacker
Author by

stacker

Updated on June 05, 2022

Comments

  • stacker
    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
    stacker about 11 years
    How can I implement the drawing of the Button?
  • David Heffernan
    David Heffernan about 11 years
    The link in the answer covers that. You'll need to respond to WM_DRAWITEM.
  • sevenOfNine
    sevenOfNine almost 3 years
    10.2 Tokyo. This works only in the design mode. When I try this in source code, the color goes away.