How to make the drawing of control objects faster in a C #

Posted on

Question :

In a form, in C # for desktop, constant movements of certain controls occur.
In case I’m using PictureBox type objects, however, its rendering is very time-consuming.
Is it recommended to use another control object for this? And how can you make the movement of a given control done asynchronously?


Answer :

You can put whatever logic you want asynchronously in an object of class System.Windows.Forms.Form . But the screen update is done in an internal method that is synchronous. If you want to animate movement of controls in a form application, you are doomed to have to deal with flicker and with your thread locked while all the controls are redrawn. There is no escape.

If you really need these animations, you have three options:

  • Develop as it was in Abraham’s time : Make the form with pure C ++ without .NET, implementing your own on-screen drawing process (probably unfeasible, right?)

  • To stay in the .NET world, you can also use XNA. But XNA is more suitable for games. It seems to me to be what you’re doing (I’ve never seen productivity app, spreadsheet type or word processor with animated controls);

  • Use Windows Presentation Foundation >. It is a .NET “subframework” that has been created, among other things, for needs like yours. This is the tip;)

Leave a Reply

Your email address will not be published. Required fields are marked *