The easiest way is to call the GetWindowPlacement function. This returns a WINDOWPLACEMENT structure that contains information about the coordinates of the window on the screen.
Using this function instead of the Form.Location property solves the problems that you will encounter with multiple monitors, minimized windows, strange taskbars, etc.
The attack route will be to call the GetWindowPlacement function GetWindowPlacement you close your application, save the location of the window in the registry (or where you store it) - the registry is no longer the recommended place to save the state of the application), and then when your application reopens by calling the corresponding function SetWindowPlacement to restore the window to its previous position.
Since these are native functions open using the Win32 API, and you are working in C #, you need to call them through P / Invoke. Here are the required definitions (for organizational purposes, I recommend placing them in a static class called NativeMethods ):
[StructLayout(LayoutKind.Sequential)] struct POINT { public int X; public int Y; } [StructLayout(LayoutKind.Sequential)] struct RECT { public int left; public int top; public int right; public int bottom; } [Serializable] [StructLayout(LayoutKind.Sequential)] struct WINDOWPLACEMENT { public int length; public int flags; public int showCmd; public POINT ptMinPosition; public POINT ptMaxPosition; public RECT rcNormalPosition; } [DllImport("user32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl); [DllImport("user32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
To get the current position of your window (what will you do when your application closes), use this code:
WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); wp.length = Marshal.SizeOf(wp); GetWindowPlacement(MyForm.Handle, ref wp);
Recall that I mentioned that the registry is no longer the recommended place to save application state. Since you work in .NET, you have much more powerful and versatile options. And since the WINDOWPLACEMENT class declared above is marked as [Serializable] , it would be very easy to serialize this information in the settings, and then reload it the next time you open it.