Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Windows Display settings?

Tags:

c#

windows

dpi

There is setting for Display in Windows 7 (Control Panel -> Display). It allows to change the size of the text and other items on the screen. I need to get this setting to be able to switch on/switch off some functionality in my C# application based on the setting value. Is that possible?

like image 626
newmember Avatar asked May 12 '11 11:05

newmember


People also ask

How do I get the Display menu on my screen?

To navigate the On-Screen Display (OSD) menu, use the buttons on the monitor. The monitor control buttons are usually on the right side , either on the side, front or bottom of the monitor. To access the On-Screen Display (OSD) menu, press Button 3 on the monitor.

How do I get to Display settings in Control Panel?

You can either right-click Start, and then click Control Panel or click on start and type Control Panel and click the icon that appears. In the Control Panel window, click System, and then click Display.


1 Answers

Both graphics.DpiX and DeviceCap.LOGPIXELSX return 96 on Surface Pro in all scaling levels.

Instead, I managed to calculate the scaling factor this way:

[DllImport("gdi32.dll")] static extern int GetDeviceCaps(IntPtr hdc, int nIndex); public enum DeviceCap {     VERTRES = 10,     DESKTOPVERTRES = 117,      // http://pinvoke.net/default.aspx/gdi32/GetDeviceCaps.html }     private float getScalingFactor() {     Graphics g = Graphics.FromHwnd(IntPtr.Zero);     IntPtr desktop = g.GetHdc();     int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);     int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);       float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;      return ScreenScalingFactor; // 1.25 = 125% } 
like image 77
Farshid T Avatar answered Sep 23 '22 21:09

Farshid T