3

I have an issue with the screen size. I would like to get the size of my screen from my Windows Form Program but when I do :

Rectangle bounds = Screen.AllScreens[0].Bounds;

bounds.Width = 1536 instead 1920 (my resolution screen).

Could you help me please ?

GGO
  • 2,678
  • 4
  • 20
  • 42
Sparky
  • 37
  • 1
  • 4
  • 1920 / 1536 = 1.25. That is a magic number, be sure to declare your app to be dpiAware so you don't have to be lied to. – Hans Passant Mar 06 '18 at 12:23

2 Answers2

-1
Rectangle resolution = Screen.PrimaryScreen.Bounds

does this help? Your code returns the correct screen size for me

int count = Screen.AllScreens.Count();
for (int itr = 0; itr < count; itr++) {
    Console.WriteLine("The width of screen {0} is {1}", itr, Screen.AllScreens[itr].Bounds.Width);
}

The above code will loop through all your monitors

  • It's the same. I have the same result. It's due to the DPI value (or Zoom) of 125%. (1536 * 1.25 = 1920) Thanks for you answer =) – Sparky Mar 07 '18 at 08:14
-1

Maybe try this:

Screen.PrimaryScreen.Bounds.Width;
Screen.PrimaryScreen.Bounds.Height;
Screen.PrimaryScreen.Bounds.Size;

Maybe youre selecting the wrong monitor? Because Screen is the main lib used to get screen res.

Laimonas Sutkus
  • 3,247
  • 2
  • 26
  • 47
  • It's the same. I have the same result. It's due to the DPI value (or Zoom) of 125%. (1536 * 1.25 = 1920) Thanks for you answer =) – Sparky Mar 07 '18 at 08:16