如何实倒数计时?(100分)

  • 主题发起人 主题发起人 柳枫
  • 开始时间 开始时间

柳枫

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,设计一个考试程序,考试时间为一小时,以秒为单位,一秒一秒倒数,如何实现,请教大家,谢谢!
 
用一个 timer
在 timer 的事件里 计算
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, dateUtils;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
begin
Time: TDateTime;
endTime: TDateTime;
public
procedure begin
Test;
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.begin
Test;
begin
begin
Time := Now;
endTime := IncHour(begin
Time, 1);
Timer1.Interval := 200;
Timer1.Enabled := true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
begin
Test;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
s: string;
i: integer;
time_now: TDateTime;
begin
time_now := now;
s := FormatDateTime('hh:nn:ss', endTime - time_now);
Label1.Caption := s;
i := SecondsBetween(time_now, endTime);
Label2.Caption := Format('剩余 %d 秒', );
end;

end.
 
后退
顶部