Reputation: 83
I have a WPF application and want to output the bounds and working areas of the monitors I have. The code is as follows:
foreach (var screen in Screen.AllScreens.ToList().OrderByDescending(s => s.Primary)) // Primary Screen comes first
{
Console.WriteLine("Device: " + screen.DeviceName);
Console.WriteLine("Bounds : " + screen.Bounds);
Console.WriteLine("Working Area: " + screen.WorkingArea);
}
DISPLAY1 is my primary screen, and DISPLAY2 is my secondary. Both have the same resolution: 1920 x 1080.
The weird thing is that this code gives the following output:
Device: \.\DISPLAY1 Bounds : {X=0,Y=0,Width=1920,Height=1080} Working Area: {X=0,Y=0,Width=1920,Height=1046}
Device: \.\DISPLAY2 Bounds : {X=2400,Y=0,Width=2400,Height=1350} Working Area: {X=2400,Y=0,Width=2400,Height=1308}
I have also changed the use of Screen.AllScreens with the Monitor class provided at: http://wpftutorial.net/ScreenResolutions.html but this still returns the same values. Any one ever encountered this issue?
Thanks
Joseph
Upvotes: 1
Views: 2222
Reputation: 1
When I am trying to find Scale factor from windows application it works fine but when I am trying to get scale factor from WPF it returns wrong value. I have same code in both application. scr.Bounds.Width returns different value in WPF and Windows form
internal static decimal ScalingFactor(Screen scr)
{
DEVMODE dm = new DEVMODE();
dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
EnumDisplaySettings(scr.DeviceName, -1, ref dm);
var scalingFactor = Math.Round(Decimal.Divide(dm.dmPelsWidth, scr.Bounds.Width), 2);
return scalingFactor;
}
Windows Form Output:
WPF application Output:
Upvotes: 0