Examples Delphi

Title: How to show a Progressbar in a statusbar
uses
commctrl;

type
TMyStatusBar = class(TStatusBar)
public
constructor Create(AOwner: TComponent); override;
end;
implementation
constructor TMyStatusBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csAcceptsControls];
//that's all !!
end;
Thats all! Now this component accept other components as Children and you
can put them at design-time onto the statusbar!
But I dont 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;
Progressbar1.Top := 1;
Progressbar1.Left := 1;
{
Now the Progressbar is adopted by the Statusbar.
But unfortunatley it doesnt 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 Statubars
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;
begin
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
progressbar1.Top := r.Top; //set size of
progressbar1.Left := r.Left; //Progressbar to
progressbar1.Width := r.Right - r.Left; //fit with panel
progressbar1.Height := r.Bottom - r.Top;
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.
Comments and improvements are welcome!!
Alex.schlecht@skw.com
}
uses
commctrl;
type
TMyStatusBar = class(TStatusBar)
public
constructor Create(AOwner: TComponent); override;
end;
implementation
constructor TMyStatusBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csAcceptsControls];
end;
procedure TForm1.FormShow(Sender: TObject);
var
r: TRect;
begin
Statusbar1.Perform(SB_GETRECT, 0, Integer(@R));
//Gr??e des 1. Panels ermitteln
//SB_GETRECT ben?tigt die Unit commctrl
// 0 = erstes Panel der Statusbar; 1 = zweites Panel usw.
progressbar1.Parent := Statusbar1; //Prog.Bar adoptieren
progressbar1.Top := r.Top; //Gr??e der
progressbar1.Left := r.Left; //Progressbar setzen
progressbar1.Width := r.Right - r.Left; //und an Panel anpassen
progressbar1.Height := r.Bottom - r.Top;
end;