문제

I'm having trouble getting a Child Form to centre in the Parent Form

I have tried putting the following code in the Load() event of the parent form -

frmSplash frmS = new frmSplash();
frmS.MdiParent = this;
frmS.StartPosition = FormStartPosition.CenterParent;
frmS.Show();

I have also tried setting the property for the Child Form in Visual Studio putting CentreParent as the default value.

However, the child form always appears in the top left corner of the parent form and I cannot work out why.

Anyone have any clues, or suggestions for what I might be doing wrong?

[EDIT]

After a couple of answers were posted I also tried

private void frmMain_Load(object sender, EventArgs e)
{
    try
    {
        frmSplash frmS = new frmSplash();
        frmS.MdiParent = this;
        frmS.StartPosition = FormStartPosition.CenterScreen;
        frmS.Show();
    }
    catch (Exception eX)
    {
        throw new Exception("frmMain: Load()" + Environment.NewLine + eX.Message);
    }
}

But CentreScreen does NOT work either

도움이 되었습니까?

해결책

I think CenterParent only works for Parent not for MDIParent.

Try this it works

frmS.StartPosition = FormStartPosition.CenterScreen;

다른 팁

Try changing this:

frmS.StartPosition = FormStartPosition.CenterParent;

To this:

frmS.StartPosition = FormStartPosition.CenterScreen;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top