I have a custom control's library. Now there's a control which looks like a panel, and when it opens up I want to animate its vertical growing like this:
For h As Single = 0 To finalHeight Step 0.5
Me.Height = CInt(h)
' HERE I WANT TO CALL DoEvents'
Next
Me.Height = finalHeight
If I don't call DoEvents in the loop then the animation is not shown, I only get the final height without a visual feedback along the way.
I can call DoEvents from inside my main WinForm project, but can't inside a library.
How can I do that, without drowning into the deep threads waters?
This is what I've found: the timer, even at fast intervals, it is really slow. I don't know why but the animation is very jumpy with the timer. Simplified code:
rolex = New Timer()
rolex.Interval = 150
AddHandler rolex.Tick,
Sub(sender As Object, e As EventArgs)
Me.Height += 5
If Me.Height < finalHeight Then Exit Sub
rolex.Stop()
rolex = Nothing
Me.Height = finalHeight
End Sub
rolex.Start()
Without the timer I use a loop:
For i As Single = 0 To finalHeight Step 0.5
Height = CInt(i)
Application.DoEvents()
Next
Height = finalHeight
It works now, but the problem is that the animation speed too much depends on the machine where the loop is executed. For this reason I'd like to use a Timer, but as I said it's too slow.
Any hints?