【问题标题】:Cascade the MDI forms of a Splitter panel级联拆分器面板的 MDI 形式
【发布时间】:2010-06-15 18:54:49
【问题描述】:

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

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

但问题是,如果我编写这样的代码,我将无法级联它们:

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

“this”是父表单。主窗体。

我可以级联它们吗?

谢谢大家。

【问题讨论】:

    标签: c# winforms mdi


    【解决方案1】:

    您必须覆盖 SplitContainer 面板的 LayoutEngine。 Microsoft 有一个很好的例子 here 用于创建自定义布局引擎。

    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;
    
            }
        }
    

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

    【讨论】:

    • 好的,谢谢。但我仍然不清楚如何使 CaseCade 工作?:(
    • 嗯...我无法回复代码,所以我要添加另一个答案
    猜你喜欢
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 2016-09-08
    • 2014-06-01
    • 1970-01-01
    相关资源
    最近更新 更多