(Simple?) code has me beat - Help ?

  • Thread starter Thread starter Ann Huxtable
  • Start date Start date
A

Ann Huxtable

I want to write some code to center one form over another (show one form
on top of the other). Anyone care to show me in a few lines how to do
this ?. Thanks
 
If you're showing the form using the ShowDialog method then set the form's
StartPosition to FormStartPosition.CenterParent. Otherwise, you can use code
similar to the code shown below.

Form2 f = new Form2();
f.StartPosition = FormStartPosition.Manual;
f.Location = new Point((this.Left + (this.Width / 2) - (f.Width / 2)),
(this.Top + (this.Height / 2) - (f.Height / 2)));
f.Show();
 
Tim said:
If you're showing the form using the ShowDialog method then set the form's
StartPosition to FormStartPosition.CenterParent. Otherwise, you can use code
similar to the code shown below.

Form2 f = new Form2();
f.StartPosition = FormStartPosition.Manual;
f.Location = new Point((this.Left + (this.Width / 2) - (f.Width / 2)),
(this.Top + (this.Height / 2) - (f.Height / 2)));
f.Show();

Thanks Tim - that's exactly what I needed!
 
Back
Top