C# 如何在其 windowstate= 最大化的 mdi 容器窗体中显示子窗体?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2356337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:43:12  来源:igfitidea点击:

How to show a child form within a mdi container form which its windowstate= maximized?

c#winformschildwindowmdiparent

提问by odiseh

How can I show a child form within a mdi container form which its windowstate= maximized ?

如何在其 windowstate= 最大化的 mdi 容器窗体中显示子窗体?

when I put these below lines of code when my child form is loading (by clicking on a menu Item of my Main form), the child form loses its parent position and does not show within its parent form.

当我在加载子窗体时(通过单击主窗体的菜单项)将这些代码放在代码行下方时,子窗体将失去其父位置并且不会显示在其父窗体中。

private void mnuUnit_Click(object sender, EventArgs e)
{
    frmUnit frm = new frmUnit();
    frm.MdiParent = this;
    frm.WindowState = FormWindowState.Maximized;
    frm.Show();
}

回答by Codesleuth

Did you forget to paste your code?

你忘记粘贴你的代码了吗?

To show an MDI child form as maximized, you do the following:

要将 MDI 子窗体显示为最大化,请执行以下操作:

// This is a method on the MDI parent (IsMdiContainer = true)
private void Button1_Click(object sender, EventArgs e)
{
    var myForm = new MyCustomForm();
    myForm.MdiParent = this;
    myForm.WindowState = FormWindowState.Maximized;
    myForm.Show();
}

回答by nipiv

You can set the dock style to fill and before calling show, use

您可以将停靠样式设置为填充并在调用 show 之前使用

myForm.BringToFront();