Most applications provide an area in the main application form, usually aligned at the bottom of the form, is used to display information about the application as it runs.
A TStatusBar component (located on the “Win32” from the component palette) can be used to add a status bar to the form. Panel A TStatusBar property is used to add, delete or modify the panel of the status bar (each panel is represented by the object TStatusPanel).
A TProgressBar (located on the “Win32” from the component palette) displays a simple progress bar. Progress bar provides the user with visual feedback on the progress of the application procedure.
ProgressBar in StatusBar
When placed on a form automatically aligns itself TStatusBar down (Align property = alBottom). Initially it only has one panel.
Here’s how to add a panel to panel collection (once the status bar has been added to the form, let’s say he has a default “StatusBar1″ name):
- Double-click the status bar to open the editor panel components
- Right click on the editor pane and select “Add” – This ad TStatusPanel one object collection panel. Add one more.
- Select the first panel, and use the Object Inspector, set the “Progress” for the Text property.
- Note: we have to put a progress bar to the second panel!
- Close the editor panel
To display a progress bar in the progress bar one panel, we first need to TProgressBar. Drop one on the form, leave the default name (ProgressBar1).
This is what needs to be done for the ProgressBar to be displayed in a StatusBar:
Sets the Parent property of StatusBar1 for ProgressBar1. Hint: “Owner vs. Parent”
Change the Style property of the second panel StatusBar for “psOwnerDraw“. Hint: “Owner drawing in Delphi” When set to psOwnerDraw, the content displayed in the status bar in the canvas drawn at runtime status bar by code in the event handler OnDrawPanel. Contrary to “psOwnerDraw“, the default value of “psText”, make sure the string is contained in the Text property is displayed in the status bar, using the alignment specified by the Alignment property.
Handle event OnDrawPanel of StatusBar by adding the line of code into a progress bar panel of the status bar.
Here’s the complete code:
<br />//*******************************************//<br />// Sampel Source Code Learning Delphi //<br />// How To Add a Status bar to a Progress bar //<br />// by : G. Giarto //<br />// E-Mail : support@learning-delphi.com //<br />// Website: http://www.learning-delphi.com //<br />//*******************************************//<br /><br />unit Unit1;<br /><br />interface<br /><br />uses<br />Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br />Dialogs, ComCtrls, StdCtrls;<br /><br />type<br />TForm1 = class(TForm)<br />pb1: TProgressBar;<br />btn1: TButton;<br />stat1: TStatusBar;<br />procedure FormCreate(Sender: TObject);<br />procedure stat1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;<br />const Rect: TRect);<br />procedure btn1Click(Sender: TObject);<br />private<br /> Private declarations <br />public<br /> Public declarations <br />end;<br /><br />var<br />Form1: TForm1;<br /><br />implementation<br /><br />$R *.dfm<br /><br />procedure TForm1.FormCreate(Sender: TObject);<br />var<br />ProgressBarStyle: integer;<br />begin<br />Caption := 'How To Add a Status bar to a Progress bar';<br />stat1.Panels[0].Text := 'PB';<br />stat1.Panels[1].Style := psOwnerDraw;<br />pb1.Parent := stat1;<br />ProgressBarStyle := GetWindowLong(pb1.Handle,<br />GWL_EXSTYLE);<br />ProgressBarStyle := ProgressBarStyle<br />- WS_EX_STATICEDGE;<br />SetWindowLong(pb1.Handle,<br />GWL_EXSTYLE,<br />ProgressBarStyle);<br />end;<br /><br />procedure TForm1.stat1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;<br />const Rect: TRect);<br />begin<br />if Panel = StatusBar.Panels[1] then<br />with pb1 do begin<br />Top := Rect.Top;<br />Left := Rect.Left;<br />Width := Rect.Right - Rect.Left - 15;<br />Height := Rect.Bottom - Rect.Top;<br />end;<br />end;<br /><br />procedure TForm1.btn1Click(Sender: TObject);<br />var<br />i : Integer;<br />begin<br />pb1.Position := 0;<br />pb1.Max := 100;<br />for i := 0 to 100 do<br />begin<br />pb1.Position := i;<br />Sleep(25);<br />end;<br />end;<br />end.<br />
-=Thank.you=-
How To Add a Status bar to a Progress bar
0 comments:
Post a Comment