Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Form in a control or Form as User Control

Tags:

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

like image 383
Refracted Paladin Avatar asked May 04 '09 17:05

Refracted Paladin


People also ask

What is the difference between user control and form?

User controls are a way of making a custom, reusable component. A user control can contain other controls but must be hosted by a form. Windows forms are the container for controls, including user controls. While it contains many similar attributes as a user control, it's primary purpose is to host controls.

What is an embedded form?

What is an Embedded Form? An embedded form is a way to display your form as part of your own web page, without your form users needing to click a link to Formsite.

What is user Control form in C#?

Definition of C# User Control. C# user control is defined as an implementation in programming language of C# to provide an empty control and this control can be leveraged to create other controls. This implementation provides additional flexibility to re-use controls in a large-scale web project.


2 Answers

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)

like image 176
Utensil Avatar answered Oct 05 '22 12:10

Utensil


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);
            }
like image 43
Hath Avatar answered Oct 05 '22 13:10

Hath