Results 1 to 12 of 12

Thread: StopWatch

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Location
    vietnam
    Posts
    5

    StopWatch

    i have 2 button(Start & Stop) and i want a timekeeper.Please help me.thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: StopWatch

    If you are using .NET 2.0 (please specify in future) then you have the Stopwatch class available to you. If you're using an earlier version then I've posted a simple Stopwatch class in the C# CodeBank.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2006
    Location
    vietnam
    Posts
    5

    Re: StopWatch

    thanks brother.now,i want a digital clock but pending.please help me

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: StopWatch

    use a Timer and 3 labels (or one label if you know how to do it)
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: StopWatch

    You still haven't specified which version you're using.

    As has been said, use a Windows.Forms.Timer and in its Tick event you update the Text in a Label. If you want it to look even more like a digital clock you can use the LedLabel control in the ElementsEx library in my signature.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2006
    Location
    vietnam
    Posts
    5

    Re: StopWatch

    can you demo ?i using vs2005

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: StopWatch

    Add a Timer to your form in the design Window and set its Interval property to the number of milliseconds you want between updates. Also set its Enabled property to False. Double-click it to create a Tick event handler. In that event handler place the code to set the Label's Text property to whatever it is you want displayed. Whenever you start the StopWatch you call the Start method of the Timer and whenever you stop the StopWatch you call the Stop method of the Timer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: StopWatch

    Quote Originally Posted by jmcilhinney
    Add a Timer to your form in the design Window and set its Interval property to the number of milliseconds you want between updates. Also set its Enabled property to False. Double-click it to create a Tick event handler. In that event handler place the code to set the Label's Text property to whatever it is you want displayed. Whenever you start the StopWatch you call the Start method of the Timer and whenever you stop the StopWatch you call the Stop method of the Timer.
    That's not a demo, this is "explanation"
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: StopWatch

    That's quite true. How do you demo adding controls in the designer? I'm not going to create a project and post it. Following instructions takes more thought than copying and pasting code and I'm all for that. You learn much more by doing, even if you're doing what someone else tells you to.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    New Member
    Join Date
    May 2006
    Location
    vietnam
    Posts
    5

    Re: StopWatch

    this problem i had done but i want a stopwatch similar as game minesweeper of microsoft.

  11. #11
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: StopWatch

    jmcilhinney could you also do what you described there in 1.1 Framework?

    And I think jmcilhinney explains quite well. The help he has given to me, at first I thought why not create something and send it to me it might be easier, but following the instructions made me learn better. Keep it up and thanks - Jennfer

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: StopWatch

    Quote Originally Posted by JenniferBabe
    jmcilhinney could you also do what you described there in 1.1 Framework?
    Absolutely. In VS.NET 2003 you have the advantage that the Timers.Timer component is in the Toolbox by default. For this I'd be inclined to use the Timers.Timer over the Windows.Forms.Timer because if you clear the SynchronizingObject property of the Timers.Timer it will raise its Elapsed events in a worker thread. That means that your stopwatch display will not stutter if the UI thread is busy doing something.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width