Changing The Colour Of A Component

tdk_man used Ask the Experts™
Is there an easy way to change the colour of a Delphi component when there isn't a Color property in the Object Inspector?

I have the TTrackbar component in mind (which looks awful when placed on a black form), but a method which could be applied regardless of the component would be useful.


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

As TTrackbar inherits the color of it's parent, the easiest way to do it would be to place the trackbar on a panel (e.g. the trackbar with alClient on a long narrow panel) and to give the panel the color you like.

Here's some code that exemplifies drawing a border in the trackbar:

Here you can use other system colors instead of COLOR_BTNFACE:
or declare a new color constant, e.g.:

procedure TForm1.TrackBarWndProc(var Message: TMessage);
NewColor:Cardinal = $00805C53;

and use it instead:
BtnFaceBrush := CreateSolidBrush(NewColor); //but then I'd change the name of the brush though...;)
Top Expert 2007

>the easiest way to do it would be to place the trackbar on a panel...

Just found an easier way:

Top Expert 2007
No typecast required:



Thanks for the suggestions TName.

Changing the Brush colour works, but in doing so I have unfortunately discovered that I didn't have the problem I thought I had. Sorry about that.

What I hadn't realised was that it was the border around the component which was taking the colour of the background - I just thought it was transparent. I was therefore asking how to change the colour to one which it already was - if you see what I mean?... :)

So, realising this prior posting I would have asked a different question:

"If you drop a TTrackbar component onto a black form and the background becomes black you can't see the black tickmarks. Is there any way to change the colour of them so they are visible."

Actually the ability to change the colour of the trackbar groove and thumb would be nice too - but not really important.

Forced accept.

EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial