Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may try to change the problem slightly.</p> <p>Since you do not know how long your painting will take, you cannot make an assumption about that.</p> <p>What you do know, is the amount of time you want the transition to happen, let's say 30 seconds, something like this:</p> <pre><code>private MAX_TRANSITION_TIME = 30; //seconds </code></pre> <p>At this point you can also track the amount of time it has elapsed since the start of your operation, by recording when your operation has started, let's say </p> <pre><code>private DateTime _startMoment; </code></pre> <p>Now what you can do is to make sure you have the right routine at hand and you calculate your position based on the difference between the startMoment and now</p> <pre><code>var elapsedTime = DateTime.Now.Subtract(_startMoment).Milliseconds; var elapsedPercent = elapsedTime / MAX_TRANSITION_TIME * 1000.0 ; </code></pre> <p>From now on what you can do is to paint accordingly to your percent of time elapsed.</p> <p>So after your OnPaint is done you should be able to refresh it. If you use one UI timer, you can do this:</p> <pre><code> private void onPaint(object sender, PaintEventArgs e) { Timer1.Enabled = false; //350 lines of (adjusted)code go here If (ElapsedPercent&lt;1) { Timer1.Enabled=True; } else { // you may need to perform the last draw setting the ElapsedPercent // to 1. This is because it is very unlikely that your // last call will happen at the very last millisecond } } </code></pre> <p>Where Timer1 has to be the Timer control.</p> <p>In the Interval event you just write</p> <pre><code> _startMoment = DateTime.Now(); this.Invalidate(); </code></pre> <p>Hope this helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload