I have a windows form with many controls on it (mainly text boxes and buttons). Every time I chance the size of the form I change the size and position of the controls so that they are nicely distributed over the form. The problem is that when I change the size of the form it takes up to half a second to redraw all the controls. How can I speed this up?
I have used System.Diagnostics.Stopwatch
to time my code and I think that the part that is taking a long time is actually the drawing of the controls on screen (since the math I am doing is completed in less than a millisecond). I have also optimized it so controls are only redrawn when necessary.
One idea I had was to use async functions to draw the controls using several different threads but I don't know much about how forms draw their controls so I don't know if this is possible. This question seems to indicate it's not possible to draw controls from another thread. (I have also never used async programming before and am not sure how I would do it so if this is possible any pointers would be appreciated).
My main questions are:
- Is it possible to use async programming to do this?
- Is there another/better way?