秒表程序问题
秒表程序,问题是刚开始运行时,Label1总是显示当前时间,怎么能让它一开始显示0,点Start后才开始计时呢?
//---------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TDateTime Last,Start;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(Button1->Caption == "Start")
{
Last= 0;
Timer1->Enabled=true;
Start=Now();
Button1->Caption="End";
}
else if (Button1->Caption=="End")
{
Last= Now()-Start + Last;
Timer1->Enabled=false;
Button1->Caption="goon";
}
else if (Button1->Caption=="goon")
{
Start=Now();
Timer1->Enabled=true;
Button1->Caption="End";
}
}
//---------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label1->Caption=FormatDateTime("hh:nn:ss:zzz",Now()-Start + Last);
}
//---------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled=false;
Label1->Caption=" ";
Button1->Caption="Start";
}
//---------------------------------------
[解决办法]
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(Button1->Caption == "Start")
{
Last= 0;
m_nClick = 0;
Timer1->Enabled=true;
Start=Now();
Button1->Caption="End";
}
...
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label1->Caption=m_nClick++;
}
[解决办法]
[code=C/C++]
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Timer1-> Enabled=false;
Label1-> Caption=0;
}
[/code]
初始化时赋值为零
[解决办法]
同上面的
[解决办法]
[Quote=引用:]
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){ Timer1-> Enabled=false; Label1-> Caption=0;}