Get and set screen resolution

How can I collect and change the screen resolution using Visual C #?

+60
c # screen screen-resolution
Feb 22 '11 at 19:01
source share
6 answers

For screen resolution, you will want to use the System.Windows.Forms.Screen class. The Screen.AllScreens property can be used to access the collection of all displays in the system, or you can use Screen.PrimaryScreen to access the main display.

The Screen class has the Bounds property, which can be used to determine the resolution of the current instance of the class, For example, to determine the resolution of the current screen:

 Rectangle resolution = Screen.PrimaryScreen.Bounds; 

To change the resolution, things get a little more complicated. This article (or this one ) provides a detailed implementation and explanation. Hope this helps.

+82
Feb 22 '11 at 19:10
source share

In C #, this is how to get screen resolution:

click the button or fill out the form:

 string screenWidth = Screen.PrimaryScreen.Bounds.Width.ToString(); string screenHeight = Screen.PrimaryScreen.Bounds.Height.ToString(); Label1.Text = ("Resolution: " + screenWidth + "x" + screenHeight); 
+10
Dec 27 '15 at 7:28
source share

This code works great in WPF. You can use it either when loading a page, or when you click a button.

  string screenWidth =System.Windows.SystemParameters.PrimaryScreenWidth.ToString(); string screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight.ToString(); txtResolution.Text ="Resolution : "+screenWidth + " X " + screenHeight; 
+4
Aug 04 '17 at 4:54 on
source share

Winforms has a Screen class that you can use to get data about screen sizes and color depth for all displays connected to a computer. Here's the docs page: http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

CHANGING the screen resolution is more complicated. There is a third-party permission class that wraps your own code that you would otherwise connect to. Use your nested CResolution class to set the screen resolution to a new height and width; but understand that this will only work for the height and width combinations that the display actually supports (800x600, 1024x768, etc., not 817x435).

+1
Feb 22 '11 at 19:08
source share

If you want to get a screen resolution, you can run the following code in the WPF window ( this will be indicated in the window):

 System.Windows.Media.Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice; Double dpiX = m.M11 * 96; Double dpiY = m.M22 * 96; 
0
Feb 22 '11 at 19:10
source share

I spent a lot of time trying to figure this out, for devices with a zoom factor it is very difficult to get the actual screen size due to the zoom factor, sometimes 125% or 150% when calls are made for C # objects, the return value is not correct now, so you need make a Windows API call to get the scaling factor and apply the multiplier, the only way I found for non-WPF applications is here

stack overflow

0
Jun 24 '19 at 2:41
source share



All Articles