Jerry Fike

Jerry Fike

  • NA
  • 107
  • 0

Positioning a Windows Form

Jan 15 2010 2:16 PM
I've been trying to figure out how to position the one  form in the c# Windows Forms Application I'm writing.  I want to simply center the form on my screen, but it always wants to position at the top left (0,0).  From some searching I've been doing, I've seen references to problems like this when using dual monitors.

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.


Answers (1)