Thread: C#

Results 1 to 5 of 5
  1. #1
    tuve2's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Swe
    Posts
    396
    Reputation
    10
    Thanks
    22
    My Mood
    Drunk

    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. -.-

  2. #2
    Vectorzz™'s Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    crossfire/mpgh.
    Posts
    655
    Reputation
    15
    Thanks
    1,911
    My Mood
    Amused
    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

  3. #3
    [HE]Περσεύς[RO]'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Location
    Hacking and Exploitation Section
    Posts
    51
    Reputation
    10
    Thanks
    6
    My Mood
    Inspired
    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.

  4. #4
    tuve2's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Swe
    Posts
    396
    Reputation
    10
    Thanks
    22
    My Mood
    Drunk
    [SOLVED]

    Code:
    double time = 0.00;
    
    button1/2:
    timer.Start/Stop
    
    timer....:
    time += 0.01;
    Just make it tiny. :P

  5. #5
    Kuro Tenshi's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    Playing Eroges/DigiArt sculpting (No ... At internship)
    Posts
    3,635
    Reputation
    70
    Thanks
    746
    My Mood
    Blah
    [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 07:32 PM.
    DigiDrawing|+ ( (Elfen Archer) )
    Link:
    http://www.mpgh.net/forum/148-showro...en-archer.html


    @ Anime Section,Otaku/weeabo (orz.) @Graphics Section, Novice DigiArtist


    neuest gift from Yura~Chan:
    http://bakyurayuu.deviantart.com/#/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