3

I have a form on which I was using the old webbrowser control. Support is going away, so I am upgrading to the new webview2 control. My entire app is scaling properly (on high DPI monitors) using these settings in the app.manifest:

  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> 
      <!-- legacy -->
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness>
      <gdiScaling>true</gdiScaling>
    </asmv3:windowsSettings>
  </asmv3:application>

Here's the problem: My webview2 control is NOT scaling. (Monitor scaled at 200%.) So when I open the form on my high DPI monitor, the webview control takes up about 25 of the total form, even though it's docked to take up the entire form. If I move the form to my non-scaled monitor, it displays properly. I tested the size of the webview control and even though it's taking up 25% of the form, the actual pixel size is the same as the form. (Form is 1200x800, Webview control is 1180x760.)

What do I need to do to make this display properly on a scaled monitor?

Screenshots: Scaled Monitor - Scaled Monitor

Un-scaled monitor - Unscaled monitor

veevan
  • 194
  • 1
  • 6
  • Have you tried with a test app, setting DpiAwareness, in app.config (``), to `PerMonitorV2`? Then scale your Form to DPI? GdiScaling is `DPI_AWARENESS_CONTEXT_UNAWARE` and uses the enhanced, System-provided, scaling for GDI only available in Windows 10 with specific compatibility settings. It's also not compatible with per-monitor awareness. -- The WebView2 Controller takes the RasterizationScale from the Top-level Window. – Jimi Aug 30 '21 at 14:58
  • Also, note that `dpiAwareness` overrides `dpiAware` (so, one or the other) and setting GdiScaling assumes Windows 10 1703+ only (`dpiAware` is then useless, if the layout of you app expects a Windows 10 System to perform GDI scaling). Also note, for testing purposes, that what you set in the `app.manifest` overrides what's in `app.config`. You didn't mention the .Net version in use (quite important). – Jimi Aug 30 '21 at 15:25
  • Answers: .Net version is 4.7.2 I set the following in app.config: ``` – veevan Aug 30 '21 at 18:52
  • More info: The current configuration of scaling options listed above (app.manifest and app.config) has provided the most compatibility with all end users who are on a WIDE variety of different windows versions, resolutions and scaling scenarios. This is literally one of about 200 different forms within a commercial application that all work without issue. Is there something specific that I can/should change that won't impact compatibility for other users but will enable this one control to scale with the ret of the app? – veevan Aug 30 '21 at 18:57
  • Your application, as it stands, it's System-Aware in Windows 7, Per Monitor-Aware in Windows 8.x, while becomes UnAware / GDI Scaled in Windows 10 (1703+). If you're using both `app.manifest` and `app.config`, what you have set in `app.config` doesn't matter, since it's overridden by the `app.manifest` settings. -- As mentioned, test using a stand-alone Project, using `app.config` only (what you have posted in your comment is ok) and set the Form that hosts the WebView2 Control to scale to DPI (`AutoScaleMode = AutoScaleMode.Dpi`). – Jimi Aug 30 '21 at 20:03
  • If the test has the desired outcome, both in a scaled monitor and in a high-dpi environment, in Systems that support WebView2, there's probably something you can do to handle that specific Form. -- You didn't say in what System(s) you have that result. Note that WebView2 is a work in progress, some of the features required to handle scaling have just been added (and you still have no real means, in managed code, to control it) -- If you have further information, add it to the question's body, not in comments. – Jimi Aug 30 '21 at 20:03

0 Answers0