Hi there everyone,
I'm trying to put a progressbar in the rightmost panel of a statusbar with 3 panels.
A. My first try was as follows:
procedure TfrmMain.AddProgressBarToStatusBar(Sender: TObject);
var
PanelRect: TRect;
begin
// Place progressbar on the statusbar
THackControl(ProgressBar1).SetParent(sbarMain);
// Retreive the rectangle of the statuspanel (in my case the second)
SendMessage(sbarMain.Handle, SB_GETRECT, 0, Integer(@PanelRect));
// Position the progressbar over the panel on the statusbar
with PanelRect do
ProgressBar1.SetBounds(Left, Top, Right - Left, Bottom - Top + 2);
end;
I then placed AddProgressBarToStatusBar in the statusbar's OnDrawPanel.
B. My second try
I'm following the example described here - Placing a TProgressBar into a TStatusBar
http://delphi.about.com/library/weekly/aa030805a.htmMy statusbar's OnDrawPanel code is as shown below:
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
//
if Panel = StatusBar.Panels[3] then
with ProgressBar1 do begin
Top := Rect.Top;
Left := Rect.Left;
Width := Rect.Right - Rect.Left - 15;
Height := StatusBar1.Height - Rect.Top + 3; //Rect.Bottom - Rect.Top;
end;
end;
In the forms' OnCreate, I put
ProgressBar1.Parent := StatusBar1;
However, in spite of all this, neither of the two tries worked. The progressbar is always shown in the first (leftmost) panel & never in the last (rightmost) panel where I want to put it.
What am I doing wrong? Thanks a lot for your assistance.
JD