views:

385

answers:

2

Does a Winform Framework exist for something similar to ASP.NET Masterpage or MS Access SubForm ?

With MS Access SubForm you can do like ASP.NET Masterpage. It's a huge loss of time with Winform when having to create a lot of complex form. You have to compensate with either Code Generation which create code duplication or do Runtime Dynamic Form which is much more difficult.

I searched on the Internet but can't find any.

+1  A: 

You can add forms to a form, or to a panel on a form.

public Form1()
{
    InitializeComponent();

    Form2 embeddedForm = new Form2();
    embeddedForm.TopLevel = false;
    Controls.Add(embeddedForm);
    embeddedForm.Show();
}

You will need to set the FormBorderStyle to None, unless you want to have an actual moveable form inside your form.

I was in a bit of a hurry at the time of posting, but Henk is right. You should consider creating a user control for this instead. Not to be confused with a custom control, which is intended for when you need to do your own drawing instead of using collections of standard Windows controls.

Thorarin
Great, I didn't know that, thanks.
programmernovice
Better to use UsetrControl for this - that is designed for this.
Henk Holterman
+4  A: 

The closes thing to Master Pages is Form Inheritance. It is regular class inheritance but also supported by the Designer. To try it:

1) Add a form with Ok and Cancel Buttons, Build project (essential)

2) Choose Project, Add new item, Windows and then the Inherited Form template. Pick the Form from step 1) as the base Form. Add some controls.

3) Repeat step 2) a few times

4) make some Buttons to show the Forms, Build and Test

5) Go back to the Form from 1) and change a few things (Background), run again


Your other tool are UserControls, they work much the same as in ASP.NET. You develop them like Forms and apply them as Controls.

Henk Holterman
Thank you, will try that also.
programmernovice