0

I set my Form's StartPosition to CenterParent. Then I change my Form.ClientSize in Form.Load() event.

Because of this my Form is not centered anymore.

Edit:

I use form.ShowDialog() to show the form.

Cencek
  • 33
  • 5

1 Answers1

0

ShowDialog() has overload that takes IWin32Window as a parameter. You can do:

myForm.ShowDialog(this);

and now access Owner.Location in myForm.Load(). Proceed by setting myForm.Location to middle of parent form minus half the width and height of myForm respectively as follows:

Location = new Point(Owner.Location.X + Owner.Width / 2 - ClientSize.Width / 2,
    Owner.Location.Y + Owner.Height / 2 - ClientSize.Height / 2)
Cencek
  • 33
  • 5