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

Progressbar in Status panels

51 views
Skip to first unread message

hamid baghi

unread,
Apr 22, 2005, 8:37:12 AM4/22/05
to
hi,
Does any body know how can I show a progress bar in a panel of statusbar?
(like internet explorer)

thanks


Finn Tolderlund

unread,
Apr 22, 2005, 8:53:43 AM4/22/05
to

"hamid baghi" <hami...@gmail.com> skrev i en meddelelse
news:4268...@newsgroups.borland.com...

> Does any body know how can I show a progress bar in a panel of statusbar?
> (like internet explorer)


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


Remy Lebeau (TeamB)

unread,
Apr 22, 2005, 2:02:32 PM4/22/05
to

"hamid baghi" <hami...@gmail.com> wrote in message
news:4268...@newsgroups.borland.com...

> 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


Finn Tolderlund

unread,
Apr 22, 2005, 2:16:17 PM4/22/05
to

"Remy Lebeau (TeamB)" <no....@no.spam.com> skrev i en meddelelse
news:42693bae$1...@newsgroups.borland.com...

> StatusBar1->Tag = 0;
> StatusBar1->Panels->Items[SomeIndex]->Style = psOwnerDraw;
> StatusBar1->Repaint();

And here I though this was a Delphi group ...
:-)
--
Finn Tolderlund


Remy Lebeau (TeamB)

unread,
Apr 22, 2005, 3:05:42 PM4/22/05
to

"Finn Tolderlund" <n...@spam.dk> wrote in message
news:42693f06$1...@newsgroups.borland.com...

> 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


0 new messages