Frage

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

War es hilfreich?

Lösung

I think CenterParent only works for Parent not for MDIParent.

Try this it works

frmS.StartPosition = FormStartPosition.CenterScreen;

Andere Tipps

Try changing this:

frmS.StartPosition = FormStartPosition.CenterParent;

To this:

frmS.StartPosition = FormStartPosition.CenterScreen;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top