0

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

Xaruth
  • 4,034
  • 3
  • 19
  • 26
PJW
  • 5,197
  • 19
  • 60
  • 74
  • The posted code works (CenterScreen version), so my guess is the frmSplash is throwing an exception. See [Why the form load can't catch exception?](http://stackoverflow.com/q/3209706/719186). – LarsTech Oct 15 '13 at 15:53

2 Answers2

2

Try changing this:

frmS.StartPosition = FormStartPosition.CenterParent;

To this:

frmS.StartPosition = FormStartPosition.CenterScreen;
Paddyd
  • 1,870
  • 16
  • 26
2

I think CenterParent only works for Parent not for MDIParent.

Try this it works

frmS.StartPosition = FormStartPosition.CenterScreen;
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189