The main screen I'm using is 1680x105 and my form is 1250,800. I've tried setting the form Location Locked property to false and the StartPosition to CenterScreen in VS 2008 std, but this didn't work.
So I thought it would be easy to do it manually. First I tried setting the properties in VS to Manual and a location of 200, 125. This didn't work -- always "upper-left". So now I'm trying to program it.
I can get my screen resolution with this:
int deskHeight = Screen.PrimaryScreen.Bounds.Height;
int deskWidth = Screen.PrimaryScreen.Bounds.Width;
MessageBox.Show("Your screen resolution is " + deskWidth + "x" + deskHeight);
.... but I'm having problems coding the statement(s) to set a position like 200, 125.
I suspect I'm really overlooking something really basic here and seem to remember doing this before without a problem, but haven't been able to find the code. Some help would really be appreciated!
[edit] Okay, I figured it out. I had the WindowState property set to Maximized. I didn't catch that because I disabled the maximize/minimize controls and was using a fixed (1250 x 800) window size. So setting it to Normal does the trick.
Hiren SoniPosted Jan 25, 2010, 12:27 AM
int deskWidth = Screen.PrimaryScreen.Bounds.Width;
// to set in center using code if centerscreen not works
int x = (deskHeight - this.Height) / 2;
int y = (deskWidth - this.Width) / 2;
this.Location = new Point(y,x);
// if you might want this , use this code
this.Location = new Point(200,125);
dont 4get to accpet answer