Easily animate your custom controls with mutimedia timer
Using the given code any control(or form) can be invalidated every millisecond (yes every 1ms not 15.6ms), so that you could animate it easily.
First add the following to your project:
Link to code
How to implement
Suppose I have a control called c1 (or a thembase):
To use the code, just add the line Implements AnimatedObject
Some errors pop up at the word 'AnimatedObject'. Just ignore them and paste this:
The above was done so that our ticker function can invalidate controls of all type since AnimatedObject is an interface, it doesn't matter what base control you've inherited.
For people who use a themebase, just do the above in the themebase else you have to add it to your control(another reason to use themebase).
How to use
In the constructor, add
This adds your control to the list of animated objects.
Similarly, in destructor ( dispose() func. ), add:
Now, when you set the animating property of your control to true, your control starts invalidating every 1ms. You can put your animation code like calculating values in the top of your onpaint() override to do it every 1ms.
To stop, just set animating=false.
Some would say why not just use a timer, for them:
About the leavemouse() sub
The leavemouse sub can be used to trigger the onmouseleave() event of a control whenever the mouse passes over another control/form.
All of the above can be added to your themebase
Credits:
Using the given code any control(or form) can be invalidated every millisecond (yes every 1ms not 15.6ms), so that you could animate it easily.
First add the following to your project:
Link to code
How to implement
Suppose I have a control called c1 (or a thembase):
PHP Code
<?php
Class c1
Inherits Control
End Class
To use the code, just add the line Implements AnimatedObject
Some errors pop up at the word 'AnimatedObject'. Just ignore them and paste this:
PHP Code
<?php
Public Property animating As Boolean Implements AnimatedObject.animating
Public ReadOnly Property designing As Boolean Implements AnimatedObject.designing
Get
Return DesignMode
End Get
End Property
Public Sub leavemouse(e As EventArgs) Implements AnimatedObject.leavemouse
OnMouseLeave(e)
End Sub
Public Sub AnimatedObject_invalidate() Implements AnimatedObject.invalidate
Invalidate()
End Sub
The above was done so that our ticker function can invalidate controls of all type since AnimatedObject is an interface, it doesn't matter what base control you've inherited.
For people who use a themebase, just do the above in the themebase else you have to add it to your control(another reason to use themebase).
How to use
In the constructor, add
PHP Code
<?php
addanimatedobject(me)
Similarly, in destructor ( dispose() func. ), add:
PHP Code
<?php
removeanimatedobject(me)
Now, when you set the animating property of your control to true, your control starts invalidating every 1ms. You can put your animation code like calculating values in the top of your onpaint() override to do it every 1ms.
To stop, just set animating=false.
Some would say why not just use a timer, for them:
- Both System.Timers.Timer and System.Threading.Timer have least period of almost 16ms. This one has almost 1ms. That's the reason why I ditched aeon's timer.
- Instead of adding a seperate instance of timer for all of your controls, even when you are using a themebase, all invalidations are done by 1 timer (had to put it in a module)
- IDK, I like to use stuff coded my myself :P
About the leavemouse() sub
The leavemouse sub can be used to trigger the onmouseleave() event of a control whenever the mouse passes over another control/form.
All of the above can be added to your themebase
Credits:
- Leslie Sanford, [email protected] for multimedia timer
- Me

