Returning a timer value?

Hey all,

I have been programming C++ for some time, but I am relatively new to Windows Forms.

I know how to start and stop a timer with timer1.Start() and timer1.Stop() but what I really need is the value in between! From the minute a user clicks a button (button1_Click) the timer starts, and when a set of conditions is fulfilled (i.e. If condition1 == 1 && condition2 == 2) then the timer stops and prints out.

I have the entire program figured out, except for this one little thing.

Help out? Thanks!

Edit: Figured it out on my own ... guess nobody comes on here anymore. Took 3 hours haha.

Here's the solution for those who were wondering:

I ditched the Start/Stop and instead deleted the timer all together. I initialized three DateTime variables (Start, End, and Total).
***

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DateTime Start, End, Total;
// When you want to start the timer
Start = DateTime::Now;
//
//
// When you want to end the timer
End = DateTime::Now;
// Find total time
Total = (End - Start);

// NOTE: Exchange "textBox1" with anything you want to print out
// (e.g. label1, button1, etc.)
// This will print it out in the format HH:MM:SS.FFFFFFFF
// (Hours, Minutes, Seconds, Milliseconds)
this->textBox1->Text = Total.ToString();
Last edited on
Topic archived. No new replies allowed.