我想做个倒计时的功能,求大家帮帮忙~100分~(100分)

  • 主题发起人 主题发起人 skuk11
  • 开始时间 开始时间
S

skuk11

Unregistered / Unconfirmed
GUEST, unregistred user!
就是倒计时功能,比如我现在设定在3点关机~~
那么label9.caption:=现在时间减设定时间。。。
 
我以前写的关机程序,参考下吧
procedure Tformshutdown.xpButton1Click(Sender: TObject);

begin
DateTimePicker1.visible:=true;
if application.MessageBox('你是否决定执行本操作?','系统询问',
mb_okcancel+mb_ok)=idok then
begin
if (radiobutton1.Checked) then
shutdownsystem(ewx_shutdown)
else if (radiobutton2.Checked) then
shutdownsystem(ewx_reboot)
else if (radiobutton3.checked) then
shutdownsystem(ewx_logoff)
else if (radiobutton4.Checked) then
begin
showmessage('请在文本框设定关机时间,并确保本窗体运行中');
datetimepicker1.time:=time;

//shutdownsystem(ewx_shutdown);
end
else if (radiobutton5.Checked) then
shutdownsystem(ewx_poweroff);
end;
end;
procedure Tformshutdown.Timer1Timer(Sender: TObject);
begin
if timetostr(stime)>timetostr(time) then
radiogroup1.Caption:='离关机还有:'+timetostr(stime-time)
else
begin
radiogroup1.Color:=clred;
radiogroup1.Font.Size:=20;
i:=i-1;
radiogroup1.Caption:=('十秒关机倒记时:'+inttostr(i));
if i=0 then
shutdownsystem(ewx_shutdown);
end;
if timetostr(encodetime(0,00,10,00))=timetostr(stime-time) then
able:=true;
//rtime:=timetostr(time);
//if comparestr(rtime,ltime)=0 then 比较2字符是否相等
if able=true then
begin
radiogroup1.Color:=clred;
radiogroup1.Font.Size:=20;
i:=i-1;
radiogroup1.Caption:=('十秒关机倒记时:'+inttostr(i));
if i=0 then
shutdownsystem(ewx_poweroff);
end;
//shutdownsystem(ewx_shutdown);
end;
//else
//showmessage('请正确设定时间')

procedure Tformshutdown.DateTimePicker1Change(Sender: TObject);

begin
ltime:=timetostr(datetimepicker1.time);
stime:=datetimepicker1.time;
timer1.Enabled:=true;
end;

procedure Tformshutdown.FormCreate(Sender: TObject);
begin
able:=false;
i:=10;
end;

end.
 
你使用这样的函数可以,
hourSpan(now,DateTimePicker1.Time);
MinuteSpan(now,DateTimePicker1.Time);
可以得到小时或者分钟的倒计时。
var t:double;
setTime:tdatetime;
setTime:=strtodatetime('2006-9-5 3:00:00'); //把你的设定时间加上日期
t:=MinuteSpan(now,setTime);//SetTime是你的设定时间,注意需要包含日期。
label9.Caption:=formatfloat('0',t)+' 分钟 '+formatfloat('0',60*(t-Trunc(t)))+'秒';//显示时间差,XX分钟XX秒
 
多人接受答案了。
 
后退
顶部