views:

399

answers:

2

Okay I have a large CRUD app that uses tabs with Forms embedded in them like so -->

public static void ShowFormInContainerControl(Control ctl, Form frm)
    {
        frm.TopLevel = false;
        frm.FormBorderStyle = FormBorderStyle.None;
        frm.Dock = DockStyle.Fill;
        frm.Visible = true;
        ctl.Controls.Add(frm);
    }

I then call the below in the Form Load event of the Parent Form -->

 // Embedd the child form in the this Parent
        WinFormCustomHandling.ShowFormInContainerControl(pnlModuleHost, _frmWWCModuleHost);

This was given to me HERE in response to my previous question.

As I have progressed in this I keep getting the nausiating feeling that multiple layers of embedded Forms are a disaster waiting to happen and User Controls keep popping up. Can anyone offer me some concrete advice on using user controls vs embedding forms?

See my previous question for the inspiration to this one. HERE

Also a screen shot of what my current embedded form layout looks like in action can be found HERE.

Thank You

+3  A: 

My viewpoint is that it probably won't matter too much which direction you choose. I would choose to go with user controls simply because it is the more standard approach and would allow you greater flexibility going forward. For example, what if your client comes to you and says that they would like two tabs combined into a single tab? User controls would allow you to plop those two controls onto a single tab without monkeying around with combining the controls into a single form and then changing it back next month when the requirements change again.

You have a large, complicated application that has many pieces that, from what I understand, need to communicate with each other. I think the question you should be asking yourself is not, "Forms or User Controls?". The question you should be asking yourself, is, "Is this the right architecture for this app?".

I think a design that incorporated a plugin-type architecture may be more suitable for the many moving parts you have... Or you might take a look at Microsoft's Patterns and Practices Composite Application Block (CAB)

Utensil
Interesting, would it be possible for you to explain what you mean by "plugin-type" architecture? Are you referring to abstracting what the forms DO and have different interchangable UC's to perform those base functions?
Refracted Paladin
Here is a great article on designing your application around a extensible architecture.http://www.code-magazine.com/Article.aspx?quickid=0801041
Utensil
+2  A: 

I would use a UserControl, its think there just simpler, you can see whats going on in the designer (if you want), Form has bunch of stuff you'll never need if your just going to use it as a view within a container.

Compare this to your method:

public static void DockControl(this Control control, UserControl userControl)
            {
                userControl.Dock = DockStyle.Fill;
                control.Controls.Clear();
                control.Controls.Add(userControl);
            }
Hath