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

放肆的年华 提交于 2019-12-11 13:07:56

问题


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

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

回答1:


Did you forget to paste your code?

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

// 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();
}



回答2:


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

myForm.BringToFront();


来源:https://stackoverflow.com/questions/2356337/how-to-show-a-child-form-within-a-mdi-container-form-which-its-windowstate-maxi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!