472,143 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

(Simple?) code has me beat - Help ?

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

Nov 24 '05 #1
3 1231
why not set both the size and locations equal?

Gabriel

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
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

Nov 24 '05 #2
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 Wilson
..NET Compact Framework MVP

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
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

Nov 24 '05 #3


Tim Wilson wrote:
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!

Nov 25 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by JKop | last post: by
176 posts views Thread by nw | last post: by
30 posts views Thread by galiorenye | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.