0

I want to add 12 small forms on a splitcontainer Panel2 of my application. That is a grid of 4x3 = 12 Forms.

So in the main Form of my application, I add a SplitContainer control. And separately I have created 12 single Forms.
To add the 12 forms to the splitcontainer, I do this:

        form1 _form1 = new form1();
        _form1.TopLevel = false;
        this.splitContainer1.Panel2.Controls.Add(_form1);
        _form1.Show();
        ....
        form12 _form12 = new form12();
        _form12.TopLevel = false;
        this.splitContainer1.Panel2.Controls.Add(_form12);
        _form12.Show();

The problem here is that All the Form (form1...form12) are displayed at the same position(Location), behing form1. So I have to move and replace each form manually

What I wanted to get is a SplitCOntainer with all the 12 forms, each one at a specific location different from each other.

So that when the SplitContainer is resizing, all the 12 forms are resizing too and when a form is closed, its pace remain empty till a new form is drap there.

Edit. I edit here to show how I solve this

        int _width = this.flowLayoutPanel1.Width;
        int _height = this.flowLayoutPanel1.Height;

        _width = (int)_width / 4;
        _height = (int)_height / 3;

        _form1.TopLevel = false;
        _form1.Width = _width;
        -form1.height = _height;
        _form1.Owner = this;
        _form1.TopLevel = false;
        flowLayoutPanel1.Controls.Add(_form1);
        _form1.Show();
....
_form12.TopLevel = false;
            _form12.Width = _width;
            -form12.height = _height;
            _form12.Owner = this;
            _form12.TopLevel = false;
            flowLayoutPanel1.Controls.Add(_form12);
            _form12.Show();

And it works as I wanted. Thanks to you for the FlowLayoutPanel introduction into SplitContainer.panel

4

1 に答える 1

3
        Form frm;
        for (int i = 0; i < 12; i++)
        {
            frm = new Form(); //generate new instance
            frm.Width = 150;
            frm.Height = 150;
            frm.Owner = this;
            frm.TopLevel = false;
            flowLayoutPanel1.Controls.Add(frm);
            frm.Show();
        }

you can used FlowlayoutPanel. simply Flowlayoutpanel add in SplitContainer1.Panel2 and set flowLayoutPanel1.dock = Fill

于 2013-01-08T04:59:55.297 に答える