[ACCEPTED]-Form.Location doesn't work-winforms

Accepted answer
Score: 26

If you wish to set the form location, you 4 have to set the form's WindowState to Normal (on any other 3 setting, the location is set for you according 2 to the rules of that setting, so your value 1 is ignored), and its StartPosition to Manual.

frm.WindowState = FormWindowState.Normal;
frm.StartPosition = FormStartPosition.Manual;
frm.BringToFront();
frm.Location = new Point(-4, -30);
Score: 2

I suppose the forms are moved by the code 18 that handles the Show() (and BringToFront) requests, so 17 you really cannot set the form's location 16 - neither before nor after calling the method 15 - because the form location will be updated 14 after the code in your main window has executed 13 (and left control back to the window message 12 pump, in Win32 terms, basically).

I would 11 use a subclass of Form for each of your 10 forms and then add an explicit Point property 9 that indicates the fixed position where 8 that particular form is expected to be. Inside 7 this class, override the OnShown virtual 6 method (or perhaps the OnActivated method 5 too) and simply update this.Location with 4 the correct location.

That should force the 3 forms to the correct position, even if some 2 code inside windows forms changes it at 1 some time.

Score: 2

Have you tried:

this.Location

or

Form.ActiveForm.Location ?

0

Score: 1

What about using a p/Invoke to MoveWindow? The link provided 1 includes a C# example.

Score: 0

Have you tried showing the form, and then 2 adjusting the Location?

Edit: Or, have you 1 tried adjusting the Left and Top properties?

More Related questions