简体   繁体   中英

What is the best way to create dynamic GUI in .net?

I have to create Dynamic GUI in .net. My requirement is that in this GUI some portion of the GUI will change according to requirement while there is one portion which will be generic at all time. what is the best way to create this type of dynamic GUI?

The best way I've found is to use WPF and the MVVM pattern. That's kind of a vague answer, but mercy, it's kind of a vague question.

The specific technique will depend on the technology that you are using for the GUI, as others have indicated. Without specific information, the best that can be done is to specify a general process.

In general, you create a "main" form that contains the common controls and content, and also contains a blank panel into which the specific content can be added.

During execution of your program, the user will do something (click a button, make a selection from a combo box, etc.) and this will trigger the application to create a new sub-form and place it into the blank panel described above.

That's the relatively easy part. The hard part is coordination between the main form and the implanted child form. Do they share menus or tool bars? Does the child have to communicate with its parent, or the parent to the child?

We need a little more detail on your choice of UI framework in order to provide more help.

It depends entirely on what the dynamic UI is. There are many ways you can approach such a problem. Here are some examples to give you some ideas:

If it's truly dynamic (eg data driven) and therefore can be totally different every time the UI is generated, then a very easy approach is to create controls from your data (eg keep track of a Y coordinate, and every time you need a new control, create one of the appropriate type at that Y position and then add the size of the control (plus a gap) to Y). This is essentially what the code generated by the Forms designer does, so it's easy to see any number of examples by just building some example forms and looking at the generated code. A good trick for placement of these conrols is to put them within a dedicated Panel control in your UI form - that way you can move the dynamic UI anywhere you like within the parent form by just moving the panel.

If it is only "semi-dynamic", in that there is a fixed "pool" of predefined user interfaces, one of which is chosen depending on (say) the current selection, then you can build a User Control class for each of these UI "panels" and then either (a) programatically add/remove them from a main form, or (b) add them all the the main form in the designer and programatically set Visible=false or Visible=true to ensure that only one panel at a time is actually visible to the user.

You can of course embed these "dynamic" panels within a fixed bit of UI so you can freely intermix the two types of UI element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM