Board index » delphi » Statusbar/Progressbar combo

Statusbar/Progressbar combo

I was wondering if anyone has the code for programming a progress bar
into the statusbar? I had it and can't seem to remember where I put



Re:Statusbar/Progressbar combo

Andrew L. Peterson wrote in message


>I was wondering if anyone has the code for programming a progress bar
>into the statusbar? I had it and can't seem to remember where I put

I got the following the Cobb Group's Delphi Developer web-site.  It's got
some good stuff if ever you feel like browsing technical documents and
stuff.  The URL for this article is
This is just an exerpt, the whole article discusses Status bars in general.

Many applications display a progress bar to show the status of some lengthy
process. In some cases, the status bar is the perfect place to show this
kind of indicator. The most obvious example is a word processor that shows a
progress bar when the user saves the current file. You can easily add such a
feature to your Delphi applications. The VCL already provides the StatusBar
and ProgressBar components--you just need to know how to combine the two.

Placing a basic progress bar on a status bar requires creating an instance
of a ProgressBar component at runtime. The progress bar is parented to the
status bar so that it appears on top of the status bar. Before you can
create the progress bar at runtime, you need to declare a TProgressBar
pointer in your main form's class declaration. To do so, switch to your main
form's header file and type the following declaration in the private

MyProgressBar: TProgressBar;

The TProgressBar class is contained in the COMCTRLS.PAS unit. Normally,
you'd have to add ComCtrls to your form's uses statement. This step isn't
necessary here, as long as you place the status bar on the form before you
create the progress bar (a logical sequence of events). Since both classes
are in the same unit, Delphi automatically adds ComCtrls to the uses
You can now write the code to create the progress bar. Once again, the
OnCreate event handler for the form is a good place for this step. (You
could also place the code in the form's constructor.) The code to create a
typical progress bar on a form might look like this:

MyProgressBar := TProgressBar.Create(self);
MyProgressBar.Parent := StatusBar1;
MyProgressBar.Left := 2;
MyProgressBar.Top := 4;
MyProgressBar.Height := 13;
MyProgressBar.Width := 200;

Notice that we use the name of the status bar as both the owner of the
progress bar (in the progress bar's constructor) and the parent (when we
assign the Parent property). Doing so ensures that the progress bar belongs
to the status bar and appears on top of it.

When you create a component at runtime, remember to supply the values for
any properties you need to modify. Sometimes you'll want the default values;
occasionally, you must supply other values. In this case, we supply the size
and position of the progress bar but let the other properties remain at
their default values. Note that the Left and Top property values are
relative to the upper-left corner of the status bar, not the form.

At this point, the progress bar is ready to use. You can assign a value to
the Position property just as you would if the progress bar were on your
form. You can use this same technique (creating a component at runtime) to
place any type of component on your status bar.

Other Threads