Question

I am using Screen.PrimaryScreen.WorkingArea to place a popup window in the lower right corner of the primary screen. Normally, this works as it is intented to, but it has some issues when the application is being run on

  • a computer that is connected to different screens with different resolutions (like a laptop being moved between offices).
  • a computer that is an RDP server, which is connected to from clients with different resolutions (like a home computer being connected to from different offices).

It looks like the values of WorkingArea is not always up-to-date after having changed the resolution multiple (?) times in one of the above mentioned scenarios, which makes it difficult to correctly position the popup window.

Is there a way to force Screen.PrimaryScreen.WorkingArea to refresh, or is there any other ways of getting the screen resolution in a Windows Forms application that can be used instead?

Was it helpful?

Solution

You could try Pinvoke

[DllImport("user32.dll", SetLastError = false)]
static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);

RECT scBounds = new RECT();
GetWindowRect(GetDesktopWindow(), ref scBounds);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top