I''m designing an app at the moment and was thinking about how to best use the GroupBar. The issue is simple, but there are lots of ways to solve the problem. I figured I''d post here to see if there''s a consensus on the best design. Until just recently,
I''ve mainly been using Java so I know what I''d choose with Swing, but the tradeoffs may be different here. (Likewise, as with all things in software design, there is not one right answer and there are tradeoffs.)
I didn''t see anything like this in the Samples, but please let me know if I missed something. If not, it might make a good idea.
I''ve got an app with a dozen or so major areas. The details are irrelevant, so imagine Outlook with its email, groups, calendars, contacts, etc. I use a GroupBar to let users move between there areas. (Each area is pretty complex and will probably have things like tabs, docking, etc. depending on the area.)
What should happen when the user clicks on a particular GroupViewItem?
Here are some (but not all) of the possibilities:
1. Use a CardLayout (like in Java)
2. In the GroupViewItemSelected handler, remove the current panel in that space, new() the selected panel and add it to the form
3. Place an empty panel in the form to serve as the parent for all these user controls. In the GroupViewItemSelected handler, remove the current panel from that holder panel, new() the selected panel and add it to that panel
4&5. Same as 2 & 3, but instead of new()ing panels each time, hold on to them and just add or remove them
6. Something I didn''t even think of off the top of my head.
While the differences are relatively small, hopefully you folks have some feelings about the best design.
December 9, 2003 10:39 PM
(and sorry that the apostrophes appear as double quotes; I pasted from my editor and didn''t check the results)
December 10, 2003 01:29 PM
We would recommend not "newing" a Panel every time, instead just keep it around and reuse them. Then, since you would simply show one Panel at a time, and that is exactly what a CardLayout does we recommend option 1.
Some other options that we could think of:
Use a MDI setup. Where each "area" will be represented by a Child Form. Then you will simply activate the appropriate child forms in the GroupBar''s selected events.
The advantage of using child-forms is that menus and toolbars can be associated with those child-forms which will automatically merge with the main form during runtime when the child form gets activated.
If you do decide to go with the CardLayout and UserControl setup, another thing you might want to consider is whether or not you want to pull the UserControls into the main-form''s designer. Because when there are too many controls on the form, the designer slows down quite a bit during load. You should then instead initialize the CardLayout and the UserControls in code.