Krzysztof Bzoma wrote:
For school purposes i need to
make Stopwatch app
File->New C++ VCL forms app C++
which have label and 2 buttons (Start and Stop).
Find (on Standard page) and drop on the form TLabel and 2 TButton.
When i click Start timer should start
Find (on System page) and drop on the form TTimer. Its (default) name
will be Timer1.
Select Label1 and change its caption to "Please, start timer".
Select TButton1, rename it to btnStart, for example, change its caption
on "Start".
Select "Events" of the your Strat button and double click on "OnClick".
IDE will generate btnStartClick method. Place the following code in
this method:
Timer1->Start();
and about every 50ms it should
Select your Timer1 on the form and set Interval property to 50.
refresh label printing elapsed time.
In btnStartClick method add:
StartTime=Now();
Goto Form1.h and add in
private: // User declarations
or in
public: // User declarations
section a variable:
TDateTime StartTime;
Select Events of the timer and double click on OnTimer event. In newly
created Timer1Timer method add:
TDateTime ElapsedTime=Now()-StartTime;
Label1->Caption=TimeToStr(ElapsedTime);
Select TButton2, rename it to btnStop, for example, change its caption
on "Stop". Double-click on your Stop button an add in newly created
btnStopClick method:
Timer1->Stop();
Run and enjoy.
For school purposes
Select component on the form and press F1.
Study all properties, events and methods of the component.
Do it for all components on your form and form itself.
--
Alex
Connect with Us