Re: Delphi Form with gradient color

Posted by webmaster Guido on July 28, 2007

In Reply to Delphi Form gradient color posted by Dan Forrester P15960 on July 25, 2007

: Changing the background color of a Delphi form is simple: just set its property Color. But how can I set a gradient background for the form, going gradually from one color to another color?

You can specify only one color for a Delphi form, there is no standard provision for specifying gradient colors. When you want a "gradient" fill, here are a few ideas:

1. Paint the form in your code with the desired colors. This "painting" must be done each time that the form is redrawn, so do it in the OnPaint event handler. That's the most complicated way, but it's very flexible.

2. Or you put some component on the form, whose colors can be set to your liking, and that seems to sit beneath (under) the other components. That can be done by adding such a component at the very end of the design, after all the other components are already on the form. Next, set this last component's property Align to alClient (fills the entire client area of the form) and finally "send it to the background" (right click it, select Control and click on Sent to Back).

What can we use for this purpose? For example a TToolBar component, because it has all the desired properties such as GradientStartColor (set for example to clSkyBlue), GradientEndColor (set to clWhite), GradientDirection and finally DrawingStyle (that's the key property, set this to dsGradient). I've tested this with Turbo Delphi, and the result looks quite convincing.

I haven't figured out yet if this also works in other Delphi versions, I'll do my homework ;) and let you know soon in my next reply.

Related articles

       

Follow Ups