The best way in your case (with the .NET) is to create 2 timer objects, one for the "background" animation and one to pace the foreground changes.
You can have two methods, one in each of the timers (one for drawing the foreground elements and one for the background) that makes all the necessary positional changes and then you can call Invalidate() at the end of the timer_tick event.
Also important is to go to the properties page of the form and make sure double buffering is set to true.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
I draw the "background" first (in this method), and the foreground changes
The difference is twofold. First, your background (I'm guessing) probably requires a lower refresh rate. This way you can update the background only 3/4 as often or whatnot and give some of the performance to your foreground elements. Also, each timer is in its own thread. That may be one of those "for better or for worse" kind of situations. See this about having 2 timers work together.
I'm not familiar with InvalidateRect but the information I found on it would lead me to believe that you can specify a region of your window to invalidate (like if you had a rapidly changing region and perhaps didn't need to repaint the rest of the scene as often). Analogous to the way Invalidate() calls the Paint method of the form in .NET, InvalidateRect works at a more fundamental level. I don't know the details. It's a Win32 function so it means you'd have to use DllImport with it to use it with .NET (there's a MFC version too but that won't help you in this instance).
Take a look around about double buffering. I don't know the answer to that one. I know that Panel doesn't have a double-buffering property to change but I don't know whether it falls under the blanket of the entire form.
I wish I had more information for you. Poke around in the C# forum archives for the answers to some of these because they'll be directly transferable.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
Another issue: I draw the picture not directly on the Form, but on the Panel. The DoubleBuffering property is protected here :(
You might derive from Panel class and use the derived class as your Panel with DoubleBuffering enabled. Lukezzz was doing the same thing here . Though it seemed that the double-buffering did not help him too much, then again, he has 200 buttons on that derived Panel (which is a lot of buttons) and your situation might be very different.
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
You don't need the delay function, use a timer. Drag one over to your form from the ToolBox (or create it in code). Place your Move_circle method into the Paint event of the form. Within your timer call Invalidate() with each cycle which will invoke the Paint method.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581