11

I'm using different sets of controls on the same location on a form. By default all are visible=false and then certain subsets of the controls are set to visible as the user selects specific values in a combobox dropdown control.

From the user's perspective this works well since they only see the controls that are needed.

However, since the controls occupy the same location on the form it is difficult to manage these in Visual Studio design view.

Is there a way to group sets of these overlapping controls in Visual Studio so that I can select the entire subset of controls quickly and easily? Is there a way to hide certain controls in design view? Right now everything is stacked on top of each other when developing so it makes managing these controls difficult.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
Dave
  • 5,436
  • 11
  • 48
  • 74

5 Answers5

10

To get such a beast to work i would put every group into it's own UserControl. On your MainForm you stack all these UserControls above each other.

So at the MainForm you can't really get a good overview, but now you got for every group your individual designer view and in your main form you can hide the complete group by a single line of code userControl.Visible = false.

Oliver
  • 43,366
  • 8
  • 94
  • 151
  • Not sure why I didn't think of that but this works perfectly. Thanks! – Dave Jun 02 '10 at 13:22
  • I am fairly new to all this. Exactly how do I go to designer view for a GroupBox? – Bernhard Nov 17 '14 at 19:55
  • 1
    @Bernhard: Quite easily. If you double-click within the solution explorer on your form or a user control visual studio will be default open the designer view. But if you are currently looking at the code of your form or control you can also simply right click somewhere within the code and select *Design view* from the context menu. – Oliver Nov 18 '14 at 07:54
  • @Oliver But then I still see the complete form, right? Not only the GroupBox? – Bernhard Nov 18 '14 at 20:30
  • @Bernhard: That's true. But you can create a `UserControl` which can then be opened and configured by the designer on its own. After running the compiler this control will then also show up in your tool box and you can add this to your main form. – Oliver Nov 19 '14 at 07:24
  • But then all the code for controls has to go inside this class and not the main form? and you won't then have access to the main forms instance variables, etc.? – Neil Walker Jun 23 '16 at 22:30
  • @NeilWalker: In my eyes this is a pro not a cons. You better think about separation of concerns and you can give your user controls public properties and events to let data flow between them. – Oliver Jun 24 '16 at 06:57
4

A TabControl can do this, works well in design mode. You just need to hide the tabs at runtime. Check my code in this thread.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I think this idea is superior to Oliver's answer for most cases because it allows you to group controls by scenario. In almost all cases where this is applicable the controls are scenario/context specific, so this methodology makes it easier to not only view only a few controls at a time, but moreover to see only controls together that the user WOULD see together. – Max von Hippel Aug 07 '15 at 17:47
0

You can not hide them.

However you can group them in group box and using "Bring to front" and "Send to back" property deal with them.

Ram
  • 11,404
  • 15
  • 62
  • 93
0

This may sound very ordinary but my design practice and philosophy can be summarized as:

  1. If there are too many controls on one page, it is certain that they are not going to be needed simultaneously on the same page at run time. Therefore, it seems efficient to group them into user controls that can be edited on their own pages.
  2. When user controls are created separately, implementing them on a form does not even necessarily need a design page. They can be manipulated (location, size, color, etc.) in runtime S/W as in a 'Form activated' routine.
  3. Treating them as user controls not only hides them from the design page but also hides them away from the S/W and packs them in compact units (DLLs) that are far easier to handle in case of events like .NET version changes or other library changes.
  4. Having separate user control solution also gives the opportunity to pack a test program project with it where you can test the performance of the control much more accurately and do necessary improvements.
  5. This approach is more inline with OOP principles and encourages standardization and multi use of these controls.
  6. Last but not the least: If the form page is getting crowded with controls, a large monitor is certainly a must at design time, remembering VS scaling does not work all that well both in design and runtime. Even if perfect scaling was possible, the page may still not seem acceptable when the dimensions change.

For all these reasons I suggest taking advantage of user controls.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    Yes,in this context, hiding them away in the design page means that they may be kept stacked anywhere and localized in initializing S/W. A rough form diagram with just empty squares, circles ellipses, etc. with correct pixel dimensions help. (e.g. one drawn with using INKSCAPE). May sound like artwork but works fine for me. I usually have to do this, since most of my work UIs for industrial machine control, ease of use, intuitive guidance and appearance of the page is an important selling point. – Murat Tokgozlu May 04 '23 at 17:51
-1

First of all,

If you work with multiple components in same location, you can use groupboxes in your form. Then, to superimpose these groupboxes, you should edit each of your groupboxes on different place in your form screen. After the edit, you should input size and location data manually in your groupbox properties menu.

If you want to edit one of your groupbox after the set location, you can easily right click any of your groupboxes then click "send to back" and "bring in front" commands. I hope it helps.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Batu92k
  • 1
  • 2