views:

156

answers:

2

I have a zoomable form-interface like MS Word. The form contains +70 controls (Richtextbox, checkbox, etc) that are positioned all over the form.

The problem is that generating the form takes 2.5 seconds. Adding the 70 controls with panel.Controls.Add( ctrl) alone takes 1 second. (16 ms per call).

Is there a way to cache the whole blank form ? Perhaps someone smart knows another method to generate the form ?

+2  A: 

Are these controls being added through the designer, or are you adding them manually in code? If it's the latter, I would recommend calling SuspendLayout on the Form before you load the controls, then ResumeLayout(true) after you're finished loading.

Additionally, if these controls are being added while the form is visible, then suspending and resuming drawing can be a great help. See the accepted answer to this question for more info on how to do that.

EDIT

Why do you need 70 RichTextBox controls? Have you considered redesigning the form so that so many aren't required (reusing some for multiple purposes, for instance)? Have you investigated your custom control to see if any speed can be gained in your own constructor?

Adam Robinson
Hi Adam,Everything is generated manually.We are already using SuspendLayout and SuspendDrawing (WM_SETREDRAW).
Run CMD
If that's the case, then any optimization would be on the component level. It's unlikely you're going to be able to get any additional performance increases.
Adam Robinson
A: 

After lots of tracing we discovered that the constructor for a Custom Inherited RichTextbox takes 7-8 ms per call. 70 controls means 70 * 8 = 560 ms.

Cant we just copy or clone an already constructed CustomRichTextBox ? Would that make a difference ?

Run CMD
The only way to create a new object is by invoking a constructor (at some level, regardless of the design pattern being used, *something* is invoking a constructor), so "copying" the object isn't possible.
Adam Robinson
Additionally, please don't post updates to your question or comments as answers. Please edit the original question and delete this answer.
Adam Robinson