views:

692

answers:

3

In java swing I can insert panels into panels and so on, and not have to build a brand new window for every view of my applicaiton, or mess around removing and adding controls.

Theres a panel clas sin C# however I cant see any way of creating a 'panel form' or basically just a form in form designer thats a panel and its contents.

How do I do this then and work the way I did with java swing?

A: 

Actually, you can use the panel control and set it's Dock property to Fill. That way, your panel will be the entire canvas of the form. Then, you can add child panels as needed either through code behind or through forms designer.

Bill
+1  A: 

Usually i just dock different forms within eachother setting the IsMdiContainer Property to true on the parent window. Then i create subforms that i dock using the following function:

static class FormUtil
{
    static public void showForm(Form sender, Control reciever)
    {
        sender.ControlBox = false;
        sender.FormBorderStyle = FormBorderStyle.None;
        sender.ShowInTaskbar = false;
        sender.TopLevel = false;
        sender.Visible = true;
        sender.Dock = DockStyle.Fill;

        reciever.Controls.Clear(); //clear panel first
        reciever.Controls.Add(sender);
    }

}

then whenever i need to dock a form inside a panel on the parents form i just do:

FormUtil.showForm(new SomeForm(), this.splitContainer1.Panel1);

This allows me to delegate some of the form creation to different designers. Works like a charm for me, love to hear if theres a better way of doing it.

Martijn Laarman
A: 

There's the concept of user controls which basicly provides you with a panel like designer surface , not to mention that you can create atomic forms (which can be reused) and register them as inheritable, that way you can provide inheritance too.

Nicolai Ustinov