Changing The Colour Of A Component

tdk_man
tdk_man used Ask the Experts™
on
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.

Thanks

TenBaz
Comment
Watch Question

Do more with

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

Commented:
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:
http://www.delphipages.com/threads/thread.cfm?ID=78831&G=78821

Here you can use other system colors instead of COLOR_BTNFACE:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsyscolor.asp
or declare a new color constant, e.g.:

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

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

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

Just found an easier way:

TWinControl(TrackBar1).Brush.Color:=clRed;
Top Expert 2007
Commented:
No typecast required:

TrackBar1.Brush.Color:=clRed;

Author

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.

TenBaz
Forced accept.

Computer101
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