Insérer une ProgressBar dans le Status Panel

Including Components into a Statusbar
The TStatusbar usually does not allow to place components on itself. But
sometimes it would be very fine to add -for example- a TProgressBar on a
This Article shows how to add components to a TStatusbar and how to fit it
into one of the Statusbar-Panels.

First apologize my bad english: I'm a programmer, not a translator ;-)
There are (at least) two ways to add Components on your Statusbar:

1. Create an own Statusbar-Object


Create your own Statusbar and allow to add components on it. This is
possible in overriding the Create-Constructor:

TMyStatusBar = class(TStatusBar)


const ructor Create(AOwner: TComponent); override;



const ructor TMyStatusBar.Create(AOwner: TComponent);

inherited Create(AOwner);

ControlStyle:= ControlStyle + [csAcceptsControls];
//that's all !!

That's all! Now this component accept other components as "Children" and you
can put them at design-time onto the statusbar!

But I don't like this way very much because you have to use this new
component. I prefer to use the "old" components and manipulating them a
little bit. So lets have a look to my favourite way:

2. "Adopt" the other component

The simplest way to include components to a statusbar is to adopt the
component! Place the TStatusbar on your Form, also place the Progressbar (or
other component you wish to include on your Statusbar) on the form (!). Then
do this in the "OnShow" Event of the Form:
Progressbar1.Parent := statusbar1; := 1;
Progressbar1.left := 1;

Now the Progressbar is "adopted" by the Statusbar.
But unfortunatley it doesn't look very nice because the Progressbar is
larger than the panel and the position is not correct. So we have to
determine the exact position of the Progresbar by using the Statubar's
border, width and height. (We have to add this code to the "OnShow" Event of
the form, because in the "OnCreate" event still no Handles are avalible.)

procedure TForm1.FormShow(Sender: TObject);
var r : TRect;
Statusbar1.perform(SB_GETRECT,0,integer( @R ));
//determine the size of panel 1
//SB_GETRECT needs Unit commctrl
// 0 = first Panel of Statusbar; 1 = the second and so on.
progressbar1.parent := Statusbar1; //adopt the Progressbar :=; //set size of
progressbar1.left := r.left; //Progressbar to
progressbar1.width := r.right-r.left; //fit with panel
progressbar1.height :=;
Now the Progressbar fits exactly into the first panel of the statusbar! If
you want to use the second or another panel, you only have to change the
parameter of the "perform" command.

Comments and improvements are welcome!!
Alex Schlecht
Ajouter un commentaire
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour16/11/2001
VisualisationVu 1108 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Objet
Auteur de l'article
Dav999 Dav999
connecté le 02/11/2011
1 articles dans la section
Contacter l'auteur