Created
February 22, 2019 20:20
-
-
Save relliv/3432ca6e64d60c1fbd13d4a7222ab3f8 to your computer and use it in GitHub Desktop.
C# Get Monitor Size As Inch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DllImport("gdi32.dll")] | |
static extern int GetDeviceCaps(IntPtr hdc, int nIndex); | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); // using System.Drawing; (add from referances) | |
IntPtr desktop = graphics.GetHdc(); | |
int monitorHeight = GetDeviceCaps(desktop, 6); | |
int monitorWidth = GetDeviceCaps(desktop, 4); | |
Content = $"Height: {monitorHeight} mm., Width: {monitorWidth} mm. This Monitor Size: {Math.Sqrt(Math.Pow(monitorHeight, 2) + Math.Pow(monitorWidth, 2)) / 25,4:#,##0.00} inch."; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source
Edit: required System.Drawing reference