A
A
Alexander Prokopenko2022-01-22 17:58:42
C++ / C#
Alexander Prokopenko, 2022-01-22 17:58:42

How to find out the correct screen resolution in C#?

I need to get the screen resolution for a screenshot, but when I try to get the resolution this way:

System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size


It gives me a resolution:
864x1536
although my resolution is 1080x1980.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2022-01-23
@AlexanderProkopenko

AlexanderProkopenko ,
an example from
https://www.codeproject.com/Articles/6810/Dynamic-...
despite its venerable age
it works, you may have to upgrade the project (it's easy) from the author's code
as described in
https://www. pinvoke.net/default.aspx/user32.enumdi... :

[DllImport("user32.dll")]
  public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
public struct DEVMODE1 {
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string dmDeviceName;
// детали
DEVMODE1 dm = new DEVMODE1();
User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm)) ;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question