Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get scale of screen

We can get resolution and stuff for our screen is Screen class. So, we should use Screen.WorkingArea.Width and Screen.WorkingArea.Height, if we want to place something in center of screen.

But, in Windows 8.1 (not sure about other OSs) there is possibility to scale items on screen, if they seem too small. You can check it, by calling context menu on desktop, select "Screen Resolution", and then select "Make text and other items larger or smaller".

And the problem is, that, it seems, it does actually increase screen resolution! So, Screen.WorkingArea.Width and Screen.WorkingArea.Height will give you scaled value, and point Screen.WorkingArea.Width/2 Screen.WorkingArea.Height/2 will no longer in center of actual screen (for 200% scaling this point will be on lower right corner of screen). That might screw a lot of placement of UI items.

So, is it possible to get value of scaling? I can't find any class containing this info.

like image 862
lentinant Avatar asked Sep 16 '15 11:09

lentinant


People also ask

How do I fix my screen scaling?

Select Display > Change the size of text, apps, and other items, and then adjust the slider for each monitor. Right-click the application, select Properties, select the Compatibility tab, and then select the Disable display scaling on high DPI settings check box.

How do I scale my screen on Windows 10?

Go to “Start Menu > Settings > System > Display” and choose the monitor you want to scale. You can also click on “Identify” if you are unsure what monitor to select. Scroll down to the “Scale and layout” option and select a percentage from the dropdown menu.


1 Answers

Most methods to retrieve DPI depends on existing controls, which may be inconvenient sometimes. But DPI can be always retrieved from registry. In C#:

using Microsoft.Win32;
//...
var currentDPI = (int)Registry.GetValue("HKEY_CURRENT_USER\\Control Panel\\Desktop", "LogPixels", 96);

Scale will be

var scale = 96/(float)currentDPI;
like image 99
lentinant Avatar answered Nov 18 '22 04:11

lentinant