PaulOTron2000 PaulOTron2000 - 22 days ago 8
Vb.net Question

Very slow design view on a complex form with a lot of controls

Let's start with a confession: I came from a VB6 background, and I'm accustomed to coding within the events of objects on a form, and as such my code for events ends up in somewhat random order in the code window. With this habit, it's never been very important to remember the names of controls (although I name them well)... I just double click on a button in the design view, which brings me straight to the code for that control's primary event. If I forget the name of a control, I click it and view properties. It's not a habit I've moved away from.

Well, now this is catching up to me. Using VS Express 2013, I have a form that contains a HUGE number of containers-within-containers, labels, buttons, and other doohickeys. I ported my code from VS.NET Express 2008 where this wasn't a problem. But now the act of selecting any control in the design view takes around 10 seconds before I can view its properties. If I drag to resize a control, and another 10 seconds passes before I can select another control. It makes designing this form nearly impractical.

In this particular project, I'm using use a tab control (which is never visible to the user) to design many "screens" which each contain panels full of controls. The panels for each "screen" are moved out of the tabs and docked into the main form as requested by the user changing screens. (I'm using the term "screen" to mean a window full of controls, usually maximized.)

Within the same project, a simple modal password-change form isn't slow to edit controls visually, even if the complex form is still visible in the IDE.

My question is in three parts:

First, what the heck is it spending all that time doing?

Second, is there a setting I can tweak to improve the speed?

Third, should I give up on trying to speed it up as-is, and move each "screen" into its own form for design purposes to avoid this slowness? (It's a lot of work to do that now... see next paragraph.)

Thus far I have avoided separating "screens" onto separate forms because I don't want a new window to come up when users change screens, and because code for the controls in one screen may affect the properties of controls on other screens... In such cases I prefer not to write out

form.doohickey.text = "blah"

..but rather keep it as ...

doohickey.text = "blah"

I'm using VB but I don't think this question is VB-specific.)

Answer

I'm now answering my own question. This is the approach I've ended up using, and it helps a lot...

My overall goal was to have an interface that didn't present a lot of windows, but still presented many different "screens".

I used to place all the different controls of different "screens" on separate panels, which were each contained in separate tabs of an invisible TabControl. I would then move those panels to my main form as needed by changing their Parent property of each panel as needed. The only problem with this is that the Winforms designer got ridiculously slow as the number of controls on a form increased into the hundreds.

Now, I am now designing each "screen" as a separate form, each of which contains a panel whose Dock property = Fill. Such a panel contains everything else on the form. The form itself never becomes visible.

As needed for to view various screens, I execute:

ScreenForm.Panel1.Parent = Mainform

...or, depending on how I lay it out...

ScreenForm.Panel1.Parent = Mainform.PanelXYZ

...I also either unload or hide any panels which already exist in the panel's new container.

I was GLADLY SURPRISED to find that the code for the various events of the controls contained in the panels would still run, because such code exists in the first form's file, not the displayed form's file. Luckily, it seems I was wrong. Event code follows the control itself. I can copy/paste not only controls, but also their corresponding event code to new forms for easier development and a faster Winforms designer.

All of this is similar to a MDI interface with maximized windows, but no title bar or [X] is displayed.

Essentially I'm doing everything as I did before, except using separate forms with panels instead of separate tabs with panels. The WinForms designer is much quicker because there aren't so many controls on any form.

Comments