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]
Just make it tiny. :PCode:double time = 0.00; button1/2: timer.Start/Stop timer....: time += 0.01;
[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]
Last edited by Kuro Tenshi; 09-09-2010 at 06:32 PM.
@ Anime Section,Otaku/weeabo (orz.) @Graphics Section, Novice DigiArtist
neuest gift from Yura~Chan:
https://bakyurayuu.deviantar*****m/#/d372taw
2nd Place MOTM#9 Theme: CharMods - Combat Arms [No - Thanks] button
come on you know that don't want to push that ordinary button