Question

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

Était-ce utile?

La solution

I think CenterParent only works for Parent not for MDIParent.

Try this it works

frmS.StartPosition = FormStartPosition.CenterScreen;

Autres conseils

Try changing this:

frmS.StartPosition = FormStartPosition.CenterParent;

To this:

frmS.StartPosition = FormStartPosition.CenterScreen;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top