1

Possible Duplicate:
How do I suspend painting for a control and its children?
Winforms Double Buffering

I have a form that draws a bunch of user defined controls (81 of them) each of which contains another ten controls (total 8,100 ish). It all seems to be drawn sequentially (takes ~1 second or so).

I've looked at these two questions, and followed the ier reccomendations (setting this.DoubleBuffered = true on both the form and the custom control, and SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); on the form, but that did not appear to do anything.

Is there a way to save the paint function of the form, save it in a delegate, swap in a dummy function so that the form does not get redrawn AT ALL, and then putting the real function back and triggering it.

I assume there is a more standard way of doing this, but I was unable to find it (it is not SuspendLayout/ResumeLayout those just deal with layout logic).

How can I do this?

Community
  • 1
  • 1
soandos
  • 4,978
  • 13
  • 62
  • 96
  • 1
    @HansPassant This has nothing to do with that. It draws perfectly, just slowly. Additionally, it is not trying to pause the painting of the form. I am. How are these two questions related? – soandos Nov 04 '12 at 20:41
  • Do yourself a favor a copy/paste that code into your form, takes 30 seconds. – Hans Passant Nov 04 '12 at 20:44
  • @HansPassant It is now rendering large black squares, and then filling them all at once (still takes around a second). Does this mean that intrinsically to create all these controls takes so much time? How could I measure that? – soandos Nov 04 '12 at 20:48

1 Answers1

1

This is the answer: (a link).

But think of it. If you prevent Paint from being happened, how your UI controls should be updated when user interacts with them? There will be no button glowing, no textbox cursor flickerinig and so on.

If you are okay with that then why you just not RenderToBitmap the container of your user controls as its background image?..

Community
  • 1
  • 1
AgentFire
  • 8,944
  • 8
  • 43
  • 90