Net 2010 calling DoEvents yes I want to from the inside a custom control library

Monday 19 August 2013 - Filed under Replica Rolex

for sale custom control’s library. Now there’s a control which appears a panel, And when it opens up I want to animate its vertical growing along these lines:

For h As Single = 0 To finalHeight walk 0.5

‘ HERE i have to CALL DoEvents’Sorry, But it’s very impossible to make using DoEvents safe here. Nothing good is possible when the user closes the form while your animation is going. It will crash this course with an ObjectDisposed exception. Making DoEvents safe requires setting the form’s Enabled property to false so that the user cannot unexpectedly cause mishaps like this. A control can not equitable set the form’s Enabled property to false, specifically not for an animation.

The workaround is obvious, Just use a Timer with an process of 15 msec. Plenty fast enough to make the cartoon look smooth. there’s sample code that does this in my answer in this thread.

From of your code library. It seems that you understand or know that DoEvents is a Bad Idea, So i am not sure why you’re calling it. I’m guessing which you can spare this put inside an override like OnVisibleChanged, Or OnPaint if this is the case you will most likely not get the results you are after, As control refreshing will be suspended of these operations.

What you want to do is create a singletick timer, And on tick improve the overall height of the control then disable the timer when finalheight is reached, Or you can schedule another tick if not. and, develop a timer and put your above loop in it on each tick. Make sure you’re aware of InvokeRequired and crossthread calls depending on the kind of timer you use.

2013-08-19  »  Ronny