Winforms - how to show/hide elements in designer?

I use "Bring to front" or "Send to back" under Format > Order to manage this kind of scenario, but you're right, it kind of sucks that visibility is only runtime (AFAIK).

Cheers


I am not sure about the right way to do this, but what I do myself in these cases is to make the controls very small and later, on program run, I change their sizes and locations on start.


Several options here:

  1. Use the Document Outline view (View --> Other Windows --> Document Outline) to select the panel you care about. You can right-click on it and choose Bring to Front to put it in front of everything else.
  2. Though it's probably not relevant to what you're doing, you might consider using a TabControl, which you can mess with visually at design time. This is only a reasonable solution if you want your users to be able to manually change which panel they're viewing.
  3. Consider moving your panels into custom UserControl classes and work on them separately. If the content and logic of these panels is reasonably self-contained then you may want to do this anyway just to better restructure your code.

Addendum: You can also use a hack that makes a TabControl's tabs invisible to the user. Put a TabControl on your form, and at run-time set the ItemSize height to 1. This makes it (almost) impossible for the user to change the tabs on their own, but still allows you to change the visible tab in the designer.

myTabControl.ItemSize = new Size(myTabControl.ItemSize.Width, 1);

Note that I called this a hack for a reason: TabControls were not meant to be used this way. It's something that appears to work, but like all hacks it may break at any time so you should only do it as a last resort (and don't blame me if it causes headaches later on...). In short, I do not recommend this hack, I only offer it as a possibility.