SwolleyMammmoth
SwolleyMammmoth

Reputation: 25

How to start timer in Visual Studio 2010 Form Application

this is my first time posting, but I was wondering how i can get a timer to increment once i start my program. I have the timer and the stop button, and i can get it to start if i have a start button to press, but i want it to start once the application is opened as there are multiple timers one after another in the game i'm making. thanks everyone. i tried searching this, but couldn't find anything. I'm still pretty new to app programming so it's not something i have done before and don't even know what to try for it.

Upvotes: 1

Views: 2315

Answers (4)

Dear XXX
Dear XXX

Reputation: 27

You can start timer on starting the program either by starting the timer in the following way:

    public Form1()
       {
        InitializeComponent();
        time.Start();
        time.Tick += time_Tick;
        } 

or by initiating the timer in Form Load Event Handler

Upvotes: 0

sudheeshix
sudheeshix

Reputation: 1591

You can start a timer by simply calling Timer.Start()

When to call this depends on the trigger. Typically you write this in an event handler, of the "button click event" like you mention, or the app's "app start event" such as the Main method, but this depends on what kind of app (WinForms?) you are writing.

Upvotes: 0

RvdV79
RvdV79

Reputation: 2022

Welcome,

I would suggest to locate the FormLoad eventhandler (either by double clicking the form or by looking in the properties window (look for the lightening icon) and search for the Load eventhandler.

Or you could try to use the FormShown eventhandler, which will be triggered when the form is actually shown instead of loaded. Depending on what you are trying to achieve, this might be a better option.

Either way, you will need to put

Timer.Start()

inside such an event handler.

Hope it helps.

Upvotes: 1

Sonny
Sonny

Reputation: 704

In Form's Load event (doubleclick on form) you can use

timer1.Start();

Upvotes: 0

Related Questions