Click here to Skip to main content
14,329,217 members
Rate this:
Please Sign up or sign in to vote.
See more:
makeing a windows form app (.net framwork)

need help to make a basic timer

What I have tried:

namespace my_first_app_dad
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            timer1.Start();
        }

        private void Totaltime_Click(object sender, EventArgs e)
        {

        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            int number = Int32.Parse(totaltime.Text);
            number =+ 1;

        }
    }
}
Posted
Updated 10-Jul-19 11:51am
v2
Comments
Dominic Burford 9-Jul-19 11:36am
   
That's just an empty function. I would suggest reading up on the docs and try again. Then if you get stuck, post an actual question which we can try to answer.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Well, you are missing quite a bit of code; and you really haven't said what your problem is so it makes it kind of hard for anyone to help you out- with the exception of those who have ESP and can read your mind.

And do you really want a timer, which is used to raise events after a specified interval; or are you looking for a stopwatch, which is used to time events?

Regardless, I do see a problem: string timer = int.Parse(timer);
timer is undefined, you are parsing is as an INT, and then putting that into a string. Seems a little sloppy.
Next thing I noticed is a stack of if...then statements; depending on how these are being used you may be better off with a switch...case structure/

Research material for you to read and then redefine your question
Timer Class (System.Windows.Forms) | Microsoft Docs[^]
Stopwatch Class (System.Diagnostics) | Microsoft Docs[^]
   
Comments
Maciej Los 9-Jul-19 15:37pm
   
5ed!
Rate this:
Please Sign up or sign in to vote.

Solution 2

Quote:
How do I make a basic timer

Assuming you want to display 'count down'/'elapsed time' to user, the solution is in 2 parts: animation and elapsing time.
- register your animation routine to the computer timer to make it launched on a regular basis as long as you want the client timer to be refreshed.
- you are using the RTC (Real Time Clock) to know what value to display.

the reason is that timer is not accurate and RTC is typically accurate to a seconde per year.
The value to display is the difference between a fixed point in time and now.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100