Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Easily animate your custom controls with mutimedia timer

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):
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) 
This adds your control to the list of animated objects.


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:
I still have to look over this, overall doesn't look bad, in my case I would have used threading.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by AnonynukSep 28, 2026 10:32 AM 2 43 Sep 28, 2026 10:32 AM
Last Post: Anonynuk
[.NET] by ExproMar 25, 2022 03:58 AM 8 733 Mar 25, 2022 03:58 AM
Last Post: SaketSaket
[.NET] by NaywynJun 7, 2020 12:33 AM 32 3,017 Jun 7, 2020 12:33 AM
Last Post: savaganka