0

I am trying to position a window to the corner of my screen. Top left corner, top right corner etc. Currently I am using the MoveWindow function below to move the screen.

 [DllImport("user32.dll", SetLastError = true)]
 static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int Width, int Height, bool Repaint);

This works however, I can't seem to find any function that reports the working area of my monitor correctly. There is always this margin that doesn't seem to get included in the position.

If I open a notepad and snap it to the left corner the top left position is -8, -8, not 0, 0, as you would think it would be.

enter image description here

Screen.PrimaryScreen.WorkingArea

reports 0,0.

IntPtr hWndDesktop = GetDesktopWindow();
RECT desktopRectangle = new RECT();
GetWindowRect(hWndDesktop, out desktopRectangle);

reports 0,0.

Screen.PrimaryScreen.Bounds

reports 0,0.

Since all these functions report 0,0, every time I move the window to that position, there is a gap between the corner of the desktop in the x and y position.

The only solution that I can seem to think of, that might work is to maximize an invisible window, and get the x,y, width, and height of it, and then use that, however it seems a bit hackish. I guess I could also - the margin value (8), but I am assuming that value won't be the same for every screen.

David Lund
  • 235
  • 1
  • 6
  • What is "snap it to the left corner"? How exactly you doing it? I know you can snap window win+arrow, but corner? – Sinatr Mar 12 '21 at 09:34
  • [Found it](https://support.microsoft.com/en-us/windows/snap-your-windows-885a9b1e-a983-a3b1-16cd-c531795e6241), you press win+left and then win+up/down afterwards. – Sinatr Mar 12 '21 at 09:38
  • 1
    When a Window is maximized, its Borders - visible or invisible - are moved outside the current Screen Bounds (so you cannot see - or *touch* - the borders of a maximized Window anymore). The `SystemInformation` class references all the current sizes of the different borders of a Window. See also the notes here: [Using SetWindowPos with multiple monitors](https://stackoverflow.com/a/53026765/7444103) – Jimi Mar 12 '21 at 09:42

0 Answers0