C# – How to design the UI for settings according to different options in C# WinForm

cnetwinforms

This is a .NET winform application question.

I come to this design from time to time. A simple form. On top of the form you have a list of options to select. According to different option chosen, the body of the form displays a unique panel of setting detail.

How to design this UI in Visual Studio neatly? I have two ideas. First idea is to have many panels, each panel contains setting controls. In runtime, hide all panels but the one according to the selection of option. In this solution, it is hard to organize the controls of the form in VS designer. You need to set the form big to hold all the panels. Panels are put one next to each other. There are many runtime loading code to write. For example, when loading the form, you need to hide panels, reset the form size. When you pick an option, you need to relocate the panels and show/hide them. Tedious!

Second idea is to use TabControl. TabControl is good because the tabs are well organized for you. You don't need to relocate panels and resize the form. All you need to do in runtime is to select the right tab according to options. One thing, you need to hide parts of the TabControl from user because after all it is not a real TabControl. Hiding the tab buttons of the TabControl is not hard but I find that after that there is always a big gap between the tab area and the following part on the form.

Dose anyone have a decent way of designing the UI? Maybe not using panels or TabControls but some smarter way? If TabControl is used most of the time, how to hide and show the tab parts of the TabControl and how to set the margin and border size of the TabControl so no big gap exists? Many thanks to any answer and suggestion.

Best Answer

When I need to do this, I put each group of controls in its own UserControl, and then I can use something else to switch between them. See, for example, Implementing a paged Options dialog on my blog.