Most applications provide an area in the application's main form, usually aligned at the bottom of a form, used to display information about the application as it runs.
A TStatusBar component (located on the "Win32" page of the component palette) can be used to add a status bar to a form. A TStatusBar's Panels property is used to add, remove or modify the panels of the status bar (each panel is represented by a TStatusPanel object).
A TProgressBar (located on the "Win32" page of the component palette) displays a simple progress bar. Progress bars provide users with visual feedback about the progress of a procedure within an application.
When placed on a form the TStatusBar automatically aligns itself to the bottom (Align property = alBottom). Initially it has just one panel.
Here's how to add panels to the Panels collection (once a status bar has been added to a form, let's say it has the default "StatusBar1" name):
To display a progress bar inside one of the Progress bar Panel's, we first need a TProgressBar. Drop one on the form, leave the default name (ProgressBar1).
Here's what needs to be done for ProgressBar to be displayed inside a StatusBar:
Here's the full code:
The first two steps in the above discussion are done in the Form's OnCreate event handler.
procedure TForm1.FormCreate(Sender: TObject); |
Note: the TProgressBar control has a default border that would look "ugly" when the component is placed in the status bar - so we decide to remove the border.
Finally, handle the OnDrawPanel event of the StatusBar1:
procedure TForm1.StatusBar1DrawPanel( |
All set. Run the project ... with some dummy code in the OnClick event handler of a Button:
procedure TForm1.Button1Click(Sender: TObject); |
Progress bar in a ListView?!
Here's how to add a progress bar to a ListView control. Plus: full source code to the TListViewEx component (TListView descendant) with ColumnResize events!
Progress bar in a message box?!
Let's say you have a standard Windows dialog box displaying a question to the user with "Yes" and "No" buttons. Wouldn't it be great if a progress bar could be displayed within a dialog box "counting" seconds until the dialog box automatically closes itself?
Here's how to place a progress bar inside a standard dialog box!
Yes, you can add any control you like to a status bar ... just follow the steps you've done with the progres bar! If you need help, be sure to post your question to the Delphi Programming Forum.
评论