所以在这里逻辑

1%=“ |”在tlabel中,一个“ |”我们需要10次循环

因此,要达到100%= 100倍” |”我们需要1000次循环

您能帮我处理代码吗?

有帮助吗?

解决方案

也许您可以使用StringOfchar函数?

这样的事情:


    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;

其他提示

我不是100%确定我的意思,但我认为这是这样的(假设“标签”是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;

我不确定重新粉刷与刷新,以及您是否应该重新粉刷/刷新整个表格,但这取决于您。

希望有帮助。

这是一个变体的O Bing解决方案,它显示了棒内部(中间)的百分比。

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;

借口我的英语不好。问候。


Neftalí-GermánEstévez-

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top