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. -.-
Originally Posted by tuve2
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
Posts 1–5 of 5 · Page 1 of 1
Post a Reply
Tags for this Thread
None
Originally Posted by tuve2
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;
}
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;
}