-3

I have a winform that I would like to open on the centre of the parent form, which is already a mdiChild (i.e. I cannot set is mdiContainer on the parent). Below is the code I use. The form I create always opens on the top-left corner of whichever parent I assign to it, which is frustrating...

        loadingCircle = new Loading(Title);
        loadingCircle.TopLevel = false;
        loadingCircle.Parent = this;
        loadingCircle.Show();
        loadingCircle.BringToFront();

I have got the StartPosition switched to CenterParent in the designer, however it does not seem to do anything...

Am I missing something obvious?

Code Vader
  • 739
  • 3
  • 9
  • 26

1 Answers1

0

To get to the center of the screen,

You can use either :

   loadingCircle.StartPosition = FormStartPosition.CenterScreen;

Or :

loadingCircle.ShowDialog();

or try this code to find center position:

  Form loadingCircle = new frmLoading();
        loadingCircle.StartPosition = FormStartPosition.Manual;
        loadingCircle.Location = new Point(this.Location.X + (this.Width - loadingCircle.Width) / 2, this.Location.Y + (this.Height - loadingCircle.Height) / 2);
        loadingCircle.Show(this);
Anoop J
  • 247
  • 1
  • 7
  • I don't want to use ShowDialog() because I still want the user to be able to interact with the UI. Any other suggestions? – Code Vader Aug 12 '16 at 07:15
  • 1
    I used a slight variation, but yes it did work! loadingCircle = new LoadingCircle(RegisterTitle); loadingCircle.TopLevel = false; loadingCircle.Parent = this; Point startPosition = new Point((this.Parent.Width / 2 - loadingCircle.Width / 2), (this.Parent.Height / 2 - loadingCircle.Height / 2)); loadingCircle.Location = startPosition; loadingCircle.Show(); loadingCircle.BringToFront(); – Code Vader Aug 18 '16 at 09:33