Author: Tomas Rutkauskas
Putting a ProgressBar on a StatusBar
Answer:
Many programs out there display a progress bar on the status bar. Internet Explorer
is one of those. However, Delphi doesn't have component with that feature built-in.
But that doesn't prevent us from having a progress bar inside a status bar panel.
This is what this trick will tech you.
To make this tip work, create a form with a StatusBar (let's accept the default
name: StatusBar1). Add a few panels to it.
To the public section of the form class declaration, add:
ProgressBar1: TProgressBar;
To the OnCreate event handler of the form, add:
1 var2 ProgressBarStyle: LongInt;
3 begin4 {create a run progress bar in the status bar}5 ProgressBar1 := TProgressBar.Create(StatusBar1);
6 ProgressBar1.Parent := StatusBar1;
7 {remove progress bar border}8 ProgressBarStyle := GetWindowLong(ProgressBar1.Handle, GWL_EXSTYLE);
9 ProgressBarStyle := ProgressBarStyle - WS_EX_STATICEDGE;
10 SetWindowLong(ProgressBar1.Handle, GWL_EXSTYLE, ProgressBarStyle);
11 {set progress bar position and size - put in Panel[2]}12 ProgressBar1.Left := StatusBar1.Panels.Items[0].Width +
13 StatusBar1.Panels.Items[1].Width + 4;
14 ProgressBar1.Top := 4;
15 ProgressBar1.Height := StatusBar1.Height - 6;
16 ProgressBar1.Width := StatusBar1.Panels.Items[2].Width - 6;
17 {set range and initial state}18 ProgressBar1.Min := 0;
19 ProgressBar1.Max := 100;
20 ProgressBar1.Step := 1;
21 ProgressBar1.Position := 0;
22 end;
23 24 //In the OnDestroy event handler of the form, add:25 26 ProgressBar1.free;
If the position of the ProgressBar within the StatusBar doesn't please you, you can change the top, left, height and width properties of the ProgressBar. You can also change the Step, Max and Min properties of the ProgressBar. Within your program, work with the progress bar as you normally would, by accessing it's Position property.