Schmidt
9/16/2011 11:58:00 AM
Am 16.09.2011 00:44, schrieb BeeJ:
> What are the pros and cons of using this code vs ploping a Timer on to a
> form? I guess this question can be generalized to all types of controls.
> Maybe more concerned about start up and shut down perils.
>
> Private WithEvents TTimer As VB.Timer '
>
> Private Sub TimerInit()
>
> Set TTimer = Controls.Add("VB.Timer", "TTimer")
> TTimer.Interval = 100 ' mSec interval
> TTimer.Enabled = True ' start TTimer
The Pros are, that you can remove such
dynamically added controls, whilst the
Form is (or remains) running.
The Timer is not the best example maybe
for such dynamic removing (it really does
not eat that much resources, whilst on a
Form) - but this can come in handy, when
you want a Form with e.g. 20+ "TabViews"
or something like that - instead of hiding
unused views (which still remain loaded then)
you could alternatively load the currently
requested tab only.
As for the removing:
To get e.g. rid of the timer when used as in
the example above, you would need to relase
it in *two* places (where the instance is
referenced from):
1: your TTimer-WithEvents-Variable
Set TTimer = Nothing
2: and you need to remove it also from the Form-
or UserControls Controls-Collection (the
thing, where you added it to).
Controls.Remove "TTimer" 'same Key as in the Add
Olaf