Skip to content

How Do I Implement VB6 Timers?

Benjamin edited this page Feb 14, 2021 · 2 revisions

Timers

When converting from VB6 to c#, you lose the gui timer object. However, c# timers can be easier with a little helper object.

There is no GUI, simply declare it from code.

First, bring in the extension:

using static VBExtension;

Next, declare an instance somewhere in a form (or wherever):

private Timer tmrMyTimer;

Finally, instantiate the timer in the class constructor:

public frmMyForm {
   InitializeComponent();
   tmrMyTimer = new Timer(tmrMyTimer_Timer);
}

And, the tmrMyTimer_Timer is just the event handler:

private void tmrMyTimer_Timer() {
   // ... Do stuff on interval
}

That's it.

The timer works more or less like the VB6 one. Use Enabled and Interval to configure and control it.

See the extension class for implementation specifics.

Clone this wiki locally