Get screen resolutions in C # class (without forms / wpf / aps.net / ...)

I do not know the .NET framework (4.5) well enough, so here is a question that I cannot find an answer to.

How to get the screen resolution of the main screen when you are not working with window forms or any other graphical environment such as WPF, Silverlight, ASP.NET, etc.? I am trying to get permission in a class library (dll) and pass it from there.

Does .NET have such features?

+6
source share
2 answers

Although you do not work in Winforms, you can still add a link to it DLL. Adding a reference to System.Windows.Forms.dll means that you can use:

 SystemInformation.VirtualScreen.Width SystemInformation.VirtualScreen.Height 
+10
source

Here is what you need.

It's too late, but I think it will be useful for another :) The answer is to use P / Invoke with SystemMetric.

You can get the size of the main screen without a link to System.Windows.Forms.dll.

http://pinvoke.net/default.aspx/Enums.SystemMetric

I don't like importing a big dll to use one simple XD method

+1
source

Source: https://habr.com/ru/post/943837/


All Articles