1

I'm a web developer with some basic experience with Windows Forms.

I need to create a Windows application with a single Form with lots of pages -I need to be able to change 100% of the content in the form several times (no pop-ups). I want the main navigation element to be a column of buttons along the left side. Those buttons should change the rest of the form.

From the searches I've done, MDI seems to be close to the solution I want.

Issues with using MDI: I don't want File Edit Window -across the top.

MOST IMPORTANT PART: There is a large, complex panel full of controls that I want to appear on several of the pages within this single Form. I want to write the panel once, but display it on multiple pages and populate it from each.

Can anyone point me toward a good template or pattern? Am I going down the wrong road with MDI?

default locale
  • 13,035
  • 13
  • 56
  • 62
  • MDI does not require menus. – SLaks Mar 06 '14 at 20:25
  • 2
    unrelated: winforms is a really old technology, not recommended for any new projects, only to maintain legacy applications. If you have experience with Web Development, you will feel much more "at home" with WPF instead of winforms. The WPF (XAML + DataBinding) paradigm is much closer to the Web paradigm than the traditional, procedural, too much code for anything winforms approach. Not to mention `Styles`, `Templates` and other XAML-related concepts that are really similar to what you see in Web Development, and have no winforms equivalents. – Federico Berasategui Mar 06 '14 at 20:28
  • Re-reading your question, I figured out that you're looking for something like [this](http://stackoverflow.com/a/18539966/643085). As you can see, easily achievable with a couple of lines of XAML, however it would take a ton of horrible hacks to achieve the same in winforms. – Federico Berasategui Mar 06 '14 at 20:37
  • Am I the only one who thinks XAML is really gross?? – We Are All Monica Mar 06 '14 at 20:41
  • @jnylen compared to winforms, it is the best thing in the world. winforms doesn't support anything and is completely useless. – Federico Berasategui Mar 06 '14 at 20:43
  • HighCore: Your "unrelated" comment is the answer I was looking for. I haven't written a windows application since 2006 and I knew of WPF but didn't realize it had completely replaced Win Forms for new projects. I am working on writing my app in WPF now and it suits my needs for layout and reusing that panel (page). It is a rough transition though -I'm struggling. Thanks for the help! – user3386408 Mar 07 '14 at 01:27

1 Answers1

1

I don't think MDI is what you want. MDI is really for applications where multiple windows need to be displayed at the same time and arranged. I don't like it very much even for those cases (I think the Visual Studio model with dockable tool windows is much nicer to use).

I would do the following:

  • Use a TabControl for the pages. This gives you the buttons, events, and a visual indicator of which page you're on for free.

    (If you don't like the TabControl for whatever reason, then define a Panel for each page (or a TabControl and hide the tabs). Then, use the button presses to hide/show pages.)

  • Create the reusable panel as a UserControl (see Control vs UserControl in WinForms?). Then you can add instances of that UserControl wherever they are needed and set the properties accordingly. You should also look for common tasks that are done to each instance of the control, and put the code for those tasks in the control itself.

Community
  • 1
  • 1
We Are All Monica
  • 13,000
  • 8
  • 46
  • 72
  • I would even say - TabControl and *not* hide the tabs, because that gives the OP the "Column of navigation buttons" – Bobson Mar 06 '14 at 20:34
  • I agree... that's what `TabControl`s are for, after all. However maybe he doesn't like the look of the built-in tabs. – We Are All Monica Mar 06 '14 at 20:35