Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use a TProgressbar within a TListbox Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
36
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to use a TProgressbar within a TListbox

Answer:

It is possible, but you have to tie the TProgressBar to the listbox at runtime, the 
listbox will not accept a component dropped on it as child. Create a new project, 
drop a TButton, TListbox, TProgressbar, TTimer on it. Set the timers Interval to 
100, its Enabled property to false. Attach handlers to the Timers OnTimer and 
buttons onClick event, complete as below:

unit Unit1;

1   interface
2   
3   uses
4     Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
5     Forms, Dialogs, stdctrls, ExtCtrls, ComCtrls;
6   
7   type
8     TForm1 = class(TForm)
9       Button1: TButton;
10      ListBox1: TListBox;
11      ProgressBar1: TProgressBar;
12      Timer1: TTimer;
13      procedure Timer1Timer(Sender: TObject);
14      procedure Button1Click(Sender: TObject);
15    private
16      { Private declarations }
17    public
18      { Public declarations }
19    end;
20  
21  var
22    Form1: TForm1;
23  
24  implementation
25  
26  {$R *.dfm}
27  
28  procedure TForm1.Timer1Timer(Sender: TObject);
29  begin
30    progressbar1.StepIt;
31    if progressbar1.Position >= progressbar1.Max then
32      timer1.enabled := false;
33  end;
34  
35  procedure TForm1.Button1Click(Sender: TObject);
36  var
37    i: integer;
38  begin
39    if timer1.Enabled then
40      exit;
41    listbox1.clear;
42    for i := 1 to 20 do
43      listbox1.Items.add(Format('Item %d', [i]));
44    progressbar1.Position := progressbar1.Min;
45    if progressbar1.Parent <> listbox1 then
46    begin
47      progressbar1.Parent := listbox1;
48      progressbar1.BoundsRect := listbox1.ItemRect(2);
49    end;
50    timer1.enabled := true;
51  end;
52  
53  end.


Build and run, click the button.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC