How to make a progress bar in Turbo Delphi using ONLY TLabel NOT TProgressBar
3 answers
Perhaps you could use the StringOfChar function?
Something like that:
procedure TForm1.Button1Click(Sender: TObject);
var
X: Integer;
Total: Integer;
Percent: Integer;
begin
Total := 1000;
for X := 1 to Total do
begin
Sleep(100);
Percent := (X * 100) div Total;
Label1.Caption := StringOfChar('|', Percent) + IntToStr(Percent) + '%';
Label1.Repaint;
end;
end;
+6
a source to share
I'm not 100% sure, I understand what you mean, but I think it is something like this (assume "label" is a TLabel):
label.caption := '';
for i := 1 to 1000 do
begin
... do stuff ...
if i mod 10 = 0 then
begin
label.caption = label.caption + '|';
label.repaint();
end;
end;
I'm not sure about redrawing and updating, and whether the whole form needs to be redrawn / updated, but that is up to you.
Hope it helps.
+3
a source to share
And this is a variation of Bing's solution showing the percentage inside (middle) of the bar.
procedure TForm1.Button1Click(Sender: TObject);
var
X: Integer;
Total: Integer;
Percent: Integer;
begin
Total := 1000;
for X := 1 to Total do begin
Sleep(5);
Percent := (X * 100) div Total;
Label1.Caption := StringOfChar('|', Percent DIV 2) +
' ' + IntToStr(Percent) + '% ' +
StringOfChar('|', Percent DIV 2);
Label1.Repaint;
Application.ProcessMessages;
end;
end;
Excuse me for my bad english. Best wishes.
Neftali-Herman Esteves -
+1
a source to share