Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 级联拆分器面板的MDI形式_C#_Winforms_Mdi - Fatal编程技术网

C# 级联拆分器面板的MDI形式

C# 级联拆分器面板的MDI形式,c#,winforms,mdi,C#,Winforms,Mdi,我在主窗体中显示我的MDI窗口,但在拆分器面板的一部分中,如下所示: Form2 f2= new Form2(); f2.MdiParent = this; f2.Parent = this.splitContainer2.Panel2; f2.Show(); this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade); 但问题是,如果我编写这样的代码,我就无法级联它们: Form2 f2= new F

我在主窗体中显示我的MDI窗口,但在拆分器面板的一部分中,如下所示:

    Form2 f2= new Form2();
    f2.MdiParent = this;
    f2.Parent = this.splitContainer2.Panel2;
    f2.Show();
this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);
但问题是,如果我编写这样的代码,我就无法级联它们:

    Form2 f2= new Form2();
    f2.MdiParent = this;
    f2.Parent = this.splitContainer2.Panel2;
    f2.Show();
this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);
“this”是父窗体。主要形式

我能把它们串起来吗


谢谢大家。

您必须覆盖SplitContainer面板的布局引擎。微软有一个创建自定义布局引擎的好例子

private void CascadeToolStripMenuItem_Click(object sender, EventArgs e) {
        //LayoutMdi(MdiLayout.Cascade);
        Rectangle bounding = this.splitContainer1.Panel1.DisplayRectangle;
        Point nextFormLocation = bounding.Location;
        foreach (Control c in this.splitContainer1.Panel1.Controls) {
            if (!c.Visible) {
                continue;
            }

            nextFormLocation.Offset(c.Margin.Left, c.Margin.Top);

            c.Location = nextFormLocation;
            c.BringToFront();

            if (c.AutoSize) {
                c.Size = c.GetPreferredSize(bounding.Size);
            }

            nextFormLocation.X = bounding.X + 20;

            nextFormLocation.Y = bounding.Y + 20;

        }
    }

只需将上述代码添加到您的cascade按钮,您就可以获得cascade的基本知识

好的,谢谢。但我仍然不清楚如何使CaseCade工作:(嗯……我不能用代码回答,所以我要添加另一个答案