How can I create a UI for settings according to different parameters in C # WinForm?

This is a .NET winform application question.

I come across this design from time to time. Simple form. At the top of the form, you have a list of options to choose from. Based on your selection, the shape body displays a unique detail settings panel.

How do I properly configure this interface in Visual Studio? I have two ideas. The first idea is to have many panels, each panel contains controls. Hide all panels at runtime, but according to your choice of option. In this solution, it is difficult to organize the form controls in VS designer. You need to set the shape to hold all the panels. The panels are placed one next to each other. There is a lot of boot code at runtime. For example, when loading a form, you need to hide the panels, reset the size of the form. When you select an option, you need to move the panels and show / hide them. Boring!

The second idea is to use a TabControl. TabControl is good because the tabs are well organized for you. You don't need to move panels and resize the form. All you have to do at runtime is select the tab you want according to the options. One thing, you need to hide the TabControl parts from the user, because this is not a real TabControl. Hiding TabControl tab buttons is not difficult, but I found that there is always a big gap between the tab area and the next part of the form after doing this.

Does anyone have a decent way to design the UI? Maybe not using panels or TabControls, but some smarter way? If the TabControl is used most of the time, how to hide and show the tabs in the TabControl and how to set the margin and border size of the TabControl, isn't there a big gap? Thanks a lot for any answer and suggestion.

+2


source to share


4 answers


When I need to do this, I put each group of controls into their own UserControl, and then I can use something else to switch between them. See, for example, Implementing a Page Settings Dialog Box on my blog.



+3


source


I suggest that you create UserControls for each of your "settings", and when the user selects an option, you load the corresponding UserControl. You may need to adjust the size of the forms, but you can easily manage all the "settings" in your development environment.



+2


source


Using custom controls is a good way to solve your problem. But you need to set them probably in the panel and play with the "Visible" and "Dock" properties.

You don't need to set them in Fill Mode in Design Mode. You can set this property at runtime or as needed.

Hope for this help.

+1


source


Sounds like you need a design template.

Why not create a UI factory that returns your UI objects as needed / required?

0


source







All Articles