PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Question about Timer component  (Read 317 times)

Imortis

  • Little Newbie
  • *
  • Posts: 3
Question about Timer component
« on: January 27, 2021, 02:59:45 PM »

Is there an example of how to use the timer Elapsed event?  I did not see anything, and I may be just be missing something simple.
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9347
  • Windows 10
    • PlanetSquires Software
Re: Question about Timer component
« Reply #1 on: January 27, 2021, 03:16:13 PM »

No problem, I have attached an extremely simple example that allows you start and stop 2 different timers. You should compile using Win32 Console or Win64 Console because the debug messages are output to the console.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Imortis

  • Little Newbie
  • *
  • Posts: 3
Re: Question about Timer component
« Reply #2 on: January 27, 2021, 03:18:21 PM »

Awesome.  Thanks for the quick response.
Logged

Imortis

  • Little Newbie
  • *
  • Posts: 3
Re: Question about Timer component
« Reply #3 on: January 28, 2021, 11:01:09 AM »

Next question.  Is there a way to reset the timer?  Just start it back a zero?  Do you need to disable and enable it to get this effect?
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9347
  • Windows 10
    • PlanetSquires Software
Re: Question about Timer component
« Reply #4 on: January 28, 2021, 12:10:30 PM »

You can start and stop the timer by manipulating the Enabled property. True will start the timer, whereas False will stop the timer. Behind the scenes the code is calling the Win32 API's SetTimer and KillTimer.

So, to reset the timer you simply need to set the Enabled property to False which effectively kills the existing timer.

Simply changing the Interval value will not reset the timer, although in hindsight, doing so on an active timer should probably effectively kill the current timer and then create a new timer reflecting the new Interval. Currently, I believe you need to Enabled=False, Interval=<value>, Enabled=True.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer