0

I wrote an application that uses a user control generating and displaying enhanced metafiles on pictureboxes. This works fine when displaying the application's forms on the PC where the application is running on. It is indispensable to remotely log into this PC using Windows remote login. In this case the display resolution and the magnification factor (can be set to 100%, 125%, 150% …) may change for the application while it is running. I found that changing the display resolution does not result in viewing the graphics in wrong size. But changing the magnification factor results in viewing graphics in the wrong size accordingly to the magnification factor.

I am searching for a solution to determine the "magnification factor". This would help to fix the problem sustainable.

I already searched for hours to find something that helps, but did not succeed:

  • Reading the resolution does not help: Dim test As Graphics = MyControl.CreateGraphics Dim Resolution As Single = test.DpiX ' Returns 96 under all conditions I also tried some API- calls with the same result (always 96 DPI).

  • Enabling / disabling DPI- awareness did not help.

  • Reading the screen resolution can help to find a factor, but this is also not sufficient, because it is not possible to distinguish between changes in resolution and changes of the magnification.

       System.Windows.SystemParameters.PrimaryScreenWidth   ' Value is updated only when starting the app
       Screen.PrimaryScreen.Bounds.Width   ' Value updated, but depends on resolution setting and magnification setting
       System.Windows.SystemParameters.PrimaryScreenWidth / Screen.PrimaryScreen.Bounds.Width ' Factor useless
    
  • *Returns 96 under all conditions* because your application is not DpiAware. Change that and it will get better: [How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?](https://stackoverflow.com/a/13228495/7444103). Metafiles may need special treatment in specific cases. But the *problem* is different. See also [High DPI support in Windows Forms](https://docs.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms) and [here](https://stackoverflow.com/a/53026765/7444103) for more info about the Screens layout and VirtualScreen. – Jimi Apr 11 '20 at 21:53
  • Replacing the EMF- graphics by a bitmap graphics solved the problem. The OS seems to treat these kinds of graphics different concerning sizes. It would be an immense effort to find out how to compensate it. – SimpleCode Jun 26 '20 at 14:51

0 Answers0