级联拆分器面板的 MDI 形式

发布于 2024-09-05 23:09:21 字数 352 浏览 0 评论 0原文

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

    Form2 f2= new Form2();
    f2.MdiParent = this;
    f2.Parent = this.splitContainer2.Panel2;
    f2.Show();

但问题是,如果我编写如下代码,则无法级联它们:

this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);

“this”是父窗体。主要形式。

我可以级联它们吗?

谢谢大家。

I am showing my MDI windows inside the main form but in one part of the splitter panel, like this:

    Form2 f2= new Form2();
    f2.MdiParent = this;
    f2.Parent = this.splitContainer2.Panel2;
    f2.Show();

but the problem is that I cannot cascade them if I write a code like this:

this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);

"this" is the parent form. the main form.

Hoe can I cascade them?

thanks all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早茶月光 2024-09-12 23:09:21

您必须重写 SplitContainer 面板的 LayoutEngine。微软有一个很好的例子 这里用于创建自定义布局引擎。

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;

        }
    }

只需将上面的代码添加到级联按钮中,您就可以了解级联的基础知识。

You'll have to override the LayoutEngine for the SplitContainer panel. Microsoft has a good example here for creating a custom layout engine.

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;

        }
    }

just add the above code to your cascade button and you'll get the basics of cascade.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文