Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to Include Components into a StatusBar Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 2.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Alex Schlecht

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 Statusbar. 

This Article shows how to add components to a TStatusbar and how to fit it into one 
of the Statusbar-Panels. 


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: 

1   type
2     TMyStatusBar = class(TStatusBar)
3     public
4       constructor Create(AOwner: TComponent); override;
5     end;
7   implementation
9   constructor TMyStatusBar.Create(AOwner: TComponent);
10  begin
11    inherited Create(AOwner);
12    ControlStyle := ControlStyle + [csAcceptsControls];
13    //that’s all !!
14  end;

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: 

15  Progressbar1.Parent := statusbar1;
16 := 1;
17  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.) 

18  procedure TForm1.FormShow(Sender: TObject);
19  var
20    r: TRect;
21  begin
22    Statusbar1.perform(SB_GETRECT, 0, integer(@R));
23    //determine the size of panel 1
25   //SB_GETRECT needs Unit commctrl
26   // 0 = first Panel of Statusbar; 1 = the second and so on.
28    progressbar1.parent := Statusbar1; //adopt the Progressbar
30 :=; //set size of
31    progressbar1.left := r.left; //Progressbar to
32    progressbar1.width := r.right - r.left; //fit with panel
33    progressbar1.height := r.bottom -;
35  end;

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. 

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC