Changing The Colour Of A Component

Posted on 2006-10-21
Last Modified: 2008-03-15
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.


Question by:tdk_man
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 28

Expert Comment

ID: 17781595
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...;)
LVL 28

Expert Comment

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

Just found an easier way:

LVL 28

Accepted Solution

TName earned 125 total points
ID: 17781710
No typecast required:


Author Comment

ID: 17783784
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.


Expert Comment

ID: 21133071
Forced accept.

EE Admin

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question