0

I have two monitor(1:3840X2160 200% scale, 2:1280X1024 100% scale)

how they look like

Then I write something to get my screen resoluton.

        System.Drawing.Rectangle entireSize = System.Drawing.Rectangle.Empty;
        foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
            Console.WriteLine(screen.Bounds.Width + "," + screen.Bounds.Height);

Here comes the confuse.

TEST1: In Winfrom, I got output

1280,1024 1920,1080

TEST2: while in WPF, it shows

2560,2048 3840,2160

TSET3: check dpi Winform: 96 WPF: 192

Here is my questions:

  1. Why dose Winform\Wpf return different resolution/DPI?
  2. Obviously '2560,2048' from wpf is not correct, but why wpf return '1280X1024 * 200%'?
  3. How can i get a same output from both winform and wpf?
magicandre1981
  • 27,895
  • 5
  • 86
  • 127
Shawn
  • 82
  • 1
  • 6
  • You're not going to get the same result from Winforms and WPF. They're fundamentally two different technologies. For starters, WPF has scaling capability; Winforms does not. – Robert Harvey Mar 31 '20 at 15:43
  • The WPF measure is scaled to the current DPI value. The WinForm measure is unscaled and your Application is not DpiAware, so the Window measures are virtualized. Dpi Awareness is active by default in WPF, it's not in WinForm. You need to activate it, setting the `app.config` or `app.manifest` (in Win10 and .Net FW 4.7.2+, you prefer the former - note that `app.manifest` overrides settings of `app.config`). See [High DPI support in Windows Forms](https://docs.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms#configuring-your-windows-forms-app-for-high-dpi-support) – Jimi Mar 31 '20 at 16:41

0 Answers0