thanks
Place a ProgressBar on your form somewhere, doesn't matter where, and set
the Visible property to False.
Create some Panels in the StatusBar and set one of the panel's Style
property to psOwnerDraw.
Create a OnDrawPanel event for the StatusBar and make it look like this:
const
PanelNumber = 1; // 0..N
procedure TMainForm.StatusBarDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
// set Panels[i].Style = psOwnerDraw (i = StatusBar.Panel where ProgressBar
should be shown)
if (StatusBar = Self.StatusBar) and (Panel =
StatusBar.Panels[PanelNumber]) then
ProgressBar.BoundsRect := Rect;
end;
That's it.
To make it simple to use the ProgressBar you can add this procedure:
procedure TMainForm.ShowProgressBar(Show: Boolean; Min, Max, Position:
Integer);
begin
if not Show then
ProgressBar.Visible := False
else
if Position > 0 then
ProgressBar.Position := Position
else
begin
ProgressBar.Min := Min;
ProgressBar.Max := Max;
ProgressBar.Position := Position;
ProgressBar.Parent := StatusBar;
ProgressBar.Visible := True;
end;
end;
Now you can do something like:
ShowProgressBar(True, 0, MaxCount, 0);
for Count := 1 to MaxCount do
begin
ShowProgressBar(True, 0, 0, Count);
{do something}
end;
ShowProgressBar(False, 0, 0, 0);
--
Finn Tolderlund
> Does any body know how can I show a progress bar in a
> panel of statusbar? (like internet explorer)
Set the Status panel's Style to psOwnerDraw, and then use the OnDrawPanel
event to render the progress. For example:
StatusBar1->Tag = 0;
StatusBar1->Panels->Items[SomeIndex]->Style = psOwnerDraw;
StatusBar1->Repaint();
//...
StatusBar1->Tag = 10;
StatusBar1->Repaint();
//..
StatusBar1->Tag = 20;
StatusBar1->Repaint();
//..
StatusBar1->Tag = 100;
StatusBar1->Repaint();
//..
StatusBar1->Panels->Items[SomeIndex]->Style = psText;
StatusBar1->Tag = 0;
StatusBar1->Repaint();
void __fastcall TForm1::StatusBar1DrawPanel(TStatusBar* StatusBar,
StatusPanel* Panel, const TRect &Rect)
{
TRect r = Rect;
r.Right = (r.Left + (Rect.Width() * (StatusBar->Tag / 100)));
StatusBar->Canvas->Brush->Color = clHighlight;
StatusBar->Canvas->FillRect(r);
r.Left = r.Right;
r.Right = Rect.Right;
StatusBar->Canvas->Brush->Color = StatusBar->Color;
StatusBar->Canvas->FillRect(r);
}
Gambit
And here I though this was a Delphi group ...
:-)
--
Finn Tolderlund
> And here I though this was a Delphi group ...
StatusBar1.Tag := 0;
StatusBar1.Panels[SomeIndex].Style := psOwnerDraw;
StatusBar1.Repaint;
//...
StatusBar1.Tag := 10;
StatusBar1.Repaint;
//..
StatusBar1.Tag := 20;
StatusBar1.Repaint;
//..
StatusBar1.Tag := 100;
StatusBar1.Repaint;
//..
StatusBar1.Panels[SomeIndex].Style := psText;
StatusBar1.Tag := 0;
StatusBar1.Repaint;
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel:
StatusPanel; const Rect: TRect);
var
R: TRect;
begin
R := Rect;
R.Right := (r.Left + (Rect.Width * (StatusBar.Tag / 100)));
StatusBar.Canvas.Brush.Color := clHighlight;
StatusBar.Canvas.FillRect(R);
R.Left := R.Right;
R.Right := Rect.Right;
StatusBar.Canvas.Brush.Color := StatusBar.Color;
StatusBar.Canvas.FillRect(R);
end;
Gambit