• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1573
  • Last Modified:

Changing The Colour Of A Component

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.


  • 3
1 Solution
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...;)
>the easiest way to do it would be to place the trackbar on a panel...

Just found an easier way:

No typecast required:

tdk_manAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now