C#

Posts 15 of 5 · Page 1 of 1
C#
I am learning C Sharp in school and got a extra task. It is that I shall make 2 buttons and the user shall press one. And press the second button and a timer shall count the time between the clicks.

I just haven't got the code. -.-
Quote Originally Posted by tuve2 View Post
I am learning C Sharp in school and got a extra task. It is that I shall make 2 buttons and the user shall press one. And press the second button and a timer shall count the time between the clicks.

I just haven't got the code. -.-
wait what? i didnt get this tbh
Quote Originally Posted by tuve2 View Post
I am learning C Sharp in school and got a extra task. It is that I shall make 2 buttons and the user shall press one. And press the second button and a timer shall count the time between the clicks.

I just haven't got the code. -.-
Read it carefully vectors... You click click the second button then click the first one a number of times. The second button activates a timer which times the space between clicks of the 1st button.. if that makes sense.

Tuve, I would help you, but I do C++, and have just started learning it at that.
[SOLVED]

Code:
double time = 0.00;

button1/2:
timer.Start/Stop

timer....:
time += 0.01;
Just make it tiny. :P
[php]
namespace simple_app
{
public partial class Form1 : Form
{
int value = 1;
int value2 = 1;
int counter = 0;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (value == 1 && value2 == 2)
{
timer1.Stop();
MessageBox.Show("The time between buttons is:\t" + counter + "\tMiliseconds");
value = 1;
value2 = 1;
}
else
{
value = 2;
}

if(value == 2)
{
timer1.Start();
}
}

private void button2_Click(object sender, EventArgs e)
{
if (value2 == 1 && value == 2)
{
timer1.Stop();
MessageBox.Show("The time between buttons is:\t" + counter + "\tMiliseconds");
value = 1;
value2 = 1;
}
else
{
value2 = 2;
}

if (value2 == 2)
{
timer1.Start();
}
}

private void timer1_Tick(object sender, EventArgs e)
{
timer1.Interval = 1;
counter++;
}
}
}
[/php]

u mean something like this? ull need 1 timer + 2 buttons. it counts miliseconds if u /1000 the value it doesnt really pop-up since it takes a while before it gets 1 sec.

here is one wich does count seconds but i used a float idk if u want to use it because aint this getting to suspisious then? ahwell u can use a double too... btw since u solved though i still made it was bored
[php]
namespace simple_app
{
public partial class Form1 : Form
{
int value = 1;
int value2 = 1;
float counter = 0;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (value == 1 && value2 == 2)
{
timer1.Stop();
MessageBox.Show("The time between buttons is:\t" + counter/1000 + "\tSeconds");
value = 1;
value2 = 1;
}
else
{
value = 2;
}

if(value == 2)
{
timer1.Start();
}
}

private void button2_Click(object sender, EventArgs e)
{
if (value2 == 1 && value == 2)
{
timer1.Stop();
MessageBox.Show("The time between buttons is:\t" + counter/1000 + "\tSeconds");
value = 1;
value2 = 1;
}
else
{
value2 = 2;
}

if (value2 == 2)
{
timer1.Start();
}
}

private void timer1_Tick(object sender, EventArgs e)
{
timer1.Interval = 1;
counter++;
}
}
}
[/php]
Posts 15 of 5 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?