Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I change color of Progress Bar?

1,706 views
Skip to first unread message

Nick Hodges (TeamB)

unread,
Aug 30, 2001, 3:56:10 PM8/30/01
to
Mike --

The TProgressBar is a wrapper around the Windows-based control, and
thus is dependent on Windows for coloring. Thus, they all have to be
the same color.

There are numerous freeware progressbars out there that will allow you
to do all sorts of customizing. Start at

http://www.torry.net

and see what you can find.


Nick Hodges - TeamB
HardThink, Inc.
Search for code at http://www.codehound.com

Mike Sandoval

unread,
Aug 30, 2001, 3:50:45 PM8/30/01
to
Help!

Does anyone know how to change the color of a progress bar? I am using four
bars in my application and I think it would be good if they were all
different colors. As far as I can tell, if I change the system highlight
color, update the bar, and then return the system color, it should work.
Unfortunately, I do not know how to change the system highlight color in
code.

Does anyone have any ideas?

Thank you for all your help.

--
Mike Sandoval

Bryan Ashby

unread,
Aug 30, 2001, 4:30:06 PM8/30/01
to
TdfsExtProgressBar on Delphifreestuff.com is a good replacement - it will
let you change the color.

Bryan Ashby

"Mike Sandoval" <m.san...@maccor.com> wrote in message
news:3b8e978b$1_1@dnews...

Mauro Patino

unread,
Aug 30, 2001, 8:23:19 PM8/30/01
to
Mike Sandoval wrote:

> Does anyone know how to change the color of a progress bar? I am using four
> bars in my application and I think it would be good if they were all
> different colors. As far as I can tell, if I change the system highlight
> color, update the bar, and then return the system color, it should work.
> Unfortunately, I do not know how to change the system highlight color in
> code.
>
> Does anyone have any ideas?

uses CommCtrl;

procedure TForm1.FormCreate(Sender: TObject);
begin
{this only works when called in constructor}
ProgressBar1.Brush.Color := clLime;

{this can be called at any time, last param is color}
SendMessage(ProgressBar1.Handle, PBM_SETBARCOLOR, 0, clRed);
end;


Peter Below (TeamB)

unread,
Aug 30, 2001, 6:47:01 PM8/30/01
to
In article <3b8e978b$1_1@dnews>, Mike Sandoval wrote:
> Does anyone know how to change the color of a progress bar? I am using four
> bars in my application and I think it would be good if they were all
> different colors. As far as I can tell, if I change the system highlight
> color, update the bar, and then return the system color, it should work.

It would not work at all. Changing a system color causes *all* controls using
this color to redraw.

The newer versions of the MS progress bar common control TProgressbar wraps
support changes of bar and background color through messages. go to
http://groups.google.com, http://www.mers.com/searchsite.html or
http://www.tamaracka.com/search.htm and search the newsgroups for
PBM_SETBARCOLOR and PBM_SETBKCOLOR, that should turn up examples. If you don't
find any search msdn.microsoft.com for the messages, i think win32.hlp does
not document them, its too old. The message constants are declared in the
CommCtrl unit.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Mike Sandoval

unread,
Aug 31, 2001, 10:19:11 AM8/31/01
to
Thanks everyone.

The following two lines of code did the trick:

ProgressBar1.Perform (PBM_SETBKCOLOR, 0, <your color here>);
ProgressBar1.Perform (PBM_SETBARCOLOR, 0, <your color here>);

I can set the background and bar colors. (I had to use the CommCtrl in my
uses declaration).

Again thanks to all who helped.

Mike


Manuel Algora

unread,
Sep 1, 2001, 2:33:41 PM9/1/01
to
I wrote one of these. Serve yourself:

UNIT dfsProgressBar;

INTERFACE

Uses
Classes, ComCtrls, Graphics;

Type
TdfsProgressBar= class(TProgressBar)

Private
FColor: TColor;
Protected
Procedure SetColor (Value: TColor);
Public
Constructor Create (AOwner: TComponent); override;
Published
Property Color: TColor
Read FColor Write SetColor;
end; // TdfsProgressbar

Procedure Register;

IMPLEMENTATION

Uses
Windows;

Constructor TdfsProgressBar.Create (AOwner: TComponent);
Begin
Inherited Create (AOwner);

FColor:= clActiveCaption;
End; // TdfsProgressBar.Create

Procedure TdfsProgressBar.SetColor (Value: TColor);
Begin
If FColor <> Value then
begin
FColor:= Value;
PostMessage(Self.Handle, $0409, 0, Value);
end;
End; // TdfsProgressBar.SetColor

Procedure Register;
Begin
RegisterComponents('DFS', [TdfsProgressBar]);
End; // Register

END.

Manuel Algora
m...@encomix.es

0 new messages