Цитата:
Сообщение от fufic
Как сделать чтобы при нажатии на первую кнопку выводился таймер на Label 1, а при нажатии на кнопку Button2 счетчик на Label 1 обнулялся и работал счетчик на Label2.
|
Положи на форму TTimer и добавь такие обработчики событий:
Код:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
case Timer1.Tag of
1:
begin
Label1.Tag := Label1.Tag + 1;
Label1.Caption := IntToStr(Label1.Tag)
end;
2:
begin
Label2.Tag := Label2.Tag + 1;
Label2.Caption := IntToStr(Label2.Tag)
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := False;
Timer1.Tag := 1;
Label1.Tag := 0;
Label1.Caption := '0';
Label2.Tag := 0;
Label2.Caption := '0';
Timer1.Enabled := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := False;
Timer1.Tag := 2;
Label1.Tag := 0;
Label1.Caption := '0';
Label2.Tag := 0;
Label2.Caption := '0';
Timer1.Enabled := True;
end;