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
and see what you can find.
Nick Hodges - TeamB
HardThink, Inc.
Search for code at http://www.codehound.com
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
"Mike Sandoval" <m.san...@maccor.com> wrote in message
news:3b8e978b$1_1@dnews...
> 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;
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.
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
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