How can I get the DPI in WPF?

https://docs.microsoft.com/en-us/archive/blogs/jaimer/getting-system-dpi-in-wpf-app seems to work PresentationSource source = PresentationSource.FromVisual(this); double dpiX, dpiY; if (source != null) { dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11; dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22; }

Detecting the system DPI/PPI from JS/CSS?

<div id=’testdiv’ style=”height: 1in; left: -100%; position: absolute; top: -100%; width: 1in;”></div> <script type=”text/javascript”> var devicePixelRatio = window.devicePixelRatio || 1; dpi_x = document.getElementById(‘testdiv’).offsetWidth * devicePixelRatio; dpi_y = document.getElementById(‘testdiv’).offsetHeight * devicePixelRatio; console.log(dpi_x, dpi_y); </script> grabbed from here http://www.infobyip.com/detectmonitordpi.php. Works on mobile devices! (android 4.2.2 tested)

getting the screen density programmatically in android?

You can get info on the display from the DisplayMetrics struct: DisplayMetrics metrics = getResources().getDisplayMetrics(); Though Android doesn’t use a direct pixel mapping, it uses a handful of quantized Density Independent Pixel values then scales to the actual screen size. So the metrics.densityDpi property will be one of the DENSITY_xxx constants (120, 160, 213, 240, … Read more

How to get Windows Display settings?

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 = … Read more

How to write WinForms code that auto-scales to system font and dpi settings?

Controls which do not support scaling properly: Label with AutoSize = False and Font inherited. Explicitly set Font on the control so it appears in bold in the Properties window. ListView column widths don’t scale. Override the form’s ScaleControl to do it instead. See this answer SplitContainer‘s Panel1MinSize, Panel2MinSize and SplitterDistance properties TextBox with MultiLine … Read more

Creating a DPI-Aware Application

EDIT: As of .NET 4.7, windows forms has improved support for High DPI. Read more about it on docs.microsoft.com It only works for Win 10 Creators Update and higher though, so it might not be feasible to use this yet depending on your user base. Difficult, but not impossible. Your best option is to move … Read more