程序中用三个按钮来控件一个label显示计时,一个开始计时,一个停止计时,一个使时间复位,
开始计时按钮代码:
timer1.Enabled:=true;
label7.Caption := FormatDateTime('hh:mm:ss', CurrentDate);
停止计时代码:
timer1.Enabled:=false;
复伴按钮代码:
if not timer1.Enabled then
begin
label7.Caption:='00:00:00';
end
else
begin
application.MessageBox('请先停止计时,再进行复位。','提示')
end;
计时器代码:
procedure TChengGoFaBu_F.Timer1Timer(Sender: TObject);
begin
CurrentDate := IncSecond(CurrentDate);
label7.Caption:=FormatDateTime('hh:mm:ss', CurrentDate);
if label7.Caption='00:01:00' then
begin
label2.Caption:='时间过去了一分钟';
beep1;
end; if label7.Caption='00:01:30' then
begin
label2.Caption:=label2.Caption+#13+'时间到';
beep2;
end;
end;问题:
=======================
停止计时后点击复位按钮可以使
label7.Caption='00:00:00'
但是再次点击开始计时按钮后时间又从上次停止时间位开始计时.
============================
我想得到的是:
停止计时后点击复位按钮,时间归为 00:00:00
再次点击开始计时按钮时,时间重新从00:00:00开始计时,要如何做才行呢?请教我,谢谢.
开始计时按钮代码:
timer1.Enabled:=true;
label7.Caption := FormatDateTime('hh:mm:ss', CurrentDate);
停止计时代码:
timer1.Enabled:=false;
复伴按钮代码:
if not timer1.Enabled then
begin
label7.Caption:='00:00:00';
end
else
begin
application.MessageBox('请先停止计时,再进行复位。','提示')
end;
计时器代码:
procedure TChengGoFaBu_F.Timer1Timer(Sender: TObject);
begin
CurrentDate := IncSecond(CurrentDate);
label7.Caption:=FormatDateTime('hh:mm:ss', CurrentDate);
if label7.Caption='00:01:00' then
begin
label2.Caption:='时间过去了一分钟';
beep1;
end; if label7.Caption='00:01:30' then
begin
label2.Caption:=label2.Caption+#13+'时间到';
beep2;
end;
end;问题:
=======================
停止计时后点击复位按钮可以使
label7.Caption='00:00:00'
但是再次点击开始计时按钮后时间又从上次停止时间位开始计时.
============================
我想得到的是:
停止计时后点击复位按钮,时间归为 00:00:00
再次点击开始计时按钮时,时间重新从00:00:00开始计时,要如何做才行呢?请教我,谢谢.
timer1.Enabled:=true
就行了
timer1.Enabled:=false;
再点开始,也就是:timer1.Enabled:=true;
并不重新开始计时的,而是从上一次的停止点累加计时,我是想重新开始计时.
var
i:Integer;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
i:=i+1;
Self.Caption :=IntToStr(i);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled :=True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled :=False;
end;
时间可复位
Timer1.Enabled:=false ;
Timer1.Enabled:= true ;
你有没有搞错哦
开始计时按钮代码:
timer1.Enabled:=true;
label7.Caption := FormatDateTime( 'hh:mm:ss ', CurrentDate);
停止计时代码:
timer1.Enabled:=false;
复伴按钮代码:
if not timer1.Enabled then
begin
label7.Caption:= '00:00:00 ';
CurrentDate:=0; //从新赋初值0end
else
begin
application.MessageBox( '请先停止计时,再进行复位。 ', '提示 ')
end;