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.

4
  • If you resize the form then you'll have to re-center it. Simple as that.
    – Dan Wilson
    Aug 21, 2018 at 13:39
  • @DanWilson - I believe that "How?" is the question. Aug 21, 2018 at 13:40
  • 2
    Why do you change the size at first?
    – Renatas M.
    Aug 21, 2018 at 13:41
  • @Reniuz I change the size because I show different content to different users.
    – Cencek
    Aug 21, 2018 at 13:49

1 Answer 1

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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.