You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bumping this to the 81 milestone as it would be a stretch to adequately test.
As a short-term workaround use the --disable-gpu-compositing command line arg and the DPI Settings of your main application process will be used instead of the DPI Awareness specified by the GPU Process.
Desktop applications using WinForms/WPF need to be made DPI Aware to run correctly on a High DPI Display (A display with a DPI Scale set greater than 100%).
Note If you mouse cursor is incorrectly positioned in the browser or the browser displays black boxes/border with rendering/resizing then your app needs to be made DPI Aware. Other parts of your application may also appear blurry or incorrectly-sized.
There are two main methods to specify the default DPI awareness of a process:
WPF applications by default have an automatically generated Program.Main entry point which makes it harder to programatically set the DPI. See https://stackoverflow.com/a/26890426/4583726 for how to create a Program.Main then you can call Cef.EnableHighDPISupport();. This must be called very early on in your application execution, preferably the first call in your custom Program.Main.
OffScreen High DPI
Add the relevant app.manifest entries or call Cef.EnableHighDPISupport() (see above for an example). Read the WinForms section above, choose which option suites your needs.
High DPI Additional Info
Chromium by default performs all rendering in separate sub-process. Specifically the GPU Compositor needs to have a DPI Awareness that matches your main application. Currently the default used by the CefSharp.BrowserSubprocess.exe is Per Monitor DPI Aware. As a workaround use the disable-gpu-compositing command line arg and the DPI Awareness of your main application process will be used instead of the DPI Awareness specified by the GPU Process (which is used for GPU Compositing). Disabling GPU Compositing may have an impact on performance, when #2927 is complete it will be possible to programatically set the DPI Awareness used by the CefSharp.BrowserSubprocess.exe
FYI, I fixed this issue for my projects by modifying the manifest in CefSharp.BrowserSubprocess.EXE to match my main applications DPI awareness. I gave the EXE a different name and set the BrowserSubprocessPath property accordingly.
Changes in Chromium (#4410) mean that the Browser and GPU processes will now be PerMonitorV2 by default,
You can override the Chromium default via setting the awareness in your app.manifest or programmatically.
The BrowserSubProcess will use the Chromium defaults starting from M111 (commit b17cd2a)
The interesting side-effect of this change is that it would appear that when set programmatically then the GPU process will mirror the awareness of the browser process (by default this is your application).
So starting in M111 you should be able to PInvoke.SHCore the awareness in your application and Chromium should respect your awareness. (Must be set before Cef.Initialze is called and before your process creates an windows/forms).
Only seems to work when set programmatically. If for some reason this doesn't work then Self Hosting the BrowserSubProcess will allow complete control.
FWIW, I am seeing this issue in .Net 8.0 Core Winforms on Windows 10 when the display is set to 125% (but not when set to 100%). I don't see it at all on Windows 11. The fix for me was to delete app.manifest, then recreate it in Visual Studio, and uncomment the
You can override the Chromium default via setting the awareness in your app.manifest or programmatically.
To revise this statement in the context of WinForms. Setting DPI Awareness via app.manifest is no longer recommended when using .Net 4.8 or greater (this includes newer versions including .Net 8.0).
I was just hunting down down the compiler warning when I saw your post. Adding Application.SetHighDpiMode(HighDpiMode.SystemAware);
To my main() method also resolved the issue. Thanks for the heads-up!
Activity
amaitland commentedon Oct 7, 2019
Should also add note that
DPI Awarenessfor a process can be viewed inTask ManageronWin10amaitland commentedon Oct 29, 2019
It might make sense to default the browsersubprocess DPI awareness to that of the main application, see how feasible that is.
amaitland commentedon Nov 27, 2019
amaitland commentedon Jan 20, 2020
Bumping this to the
81milestone as it would be a stretch to adequately test.As a short-term workaround use the
--disable-gpu-compositingcommand line arg and theDPI Settingsof your main application process will be used instead of theDPI Awarenessspecified by theGPU Process.amaitland commentedon Jan 24, 2020
Chromiumonly enablesDPI Awarenessfor the main process andGPUprocesshttps://cs.chromium.org/chromium/src/chrome/app/chrome_exe_main_win.cc?type=cs&q=base::win::EnableHighDPISupport&sq=package:chromium&g=0&l=225
https://cs.chromium.org/chromium/src/base/win/win_util.cc?type=cs&q=base::win::EnableHighDPISupport&sq=package:chromium&g=0&l=703
amaitland commentedon Mar 28, 2020
Documentation rewrite add reference to https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process#setting-default-awareness-with-the-application-manifest
Doc Rewrite (WIP)
High DPI Displays/Support
Desktop applications using
WinForms/WPFneed to be made DPI Aware to run correctly on a High DPI Display (A display with aDPI Scaleset greater than100%).Note If you mouse cursor is incorrectly positioned in the browser or the browser displays black boxes/border with rendering/resizing then your app needs to be made
DPI Aware. Other parts of your application may also appear blurry or incorrectly-sized.There are two main methods to specify the default DPI awareness of a process:
WinForms High DPI
App.manifest
Set the default awareness using the application manifest. The following example is PerMonitor DPI Aware on Win 10 1703 and above and PerMonitor DPI aware on older version. Make sure you read https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows#dpi-awareness-mode which discusses the different
DPI AwarenessoptionsProgramatically
Setting High DPI in code you can use the Cef.EnableHighDPISupport(); helper method. This calls the
Chromiumbase::win::EnableHighDPISupport(); function. You then have exactly the same settings asChromiumuses.Cef.EnableHighDPISupport(); must be called very early on in your application execution, preferably in your application entry point (Program.Main).
The CefSharp.MinimalExample.WinForms project contains a working example.
WPF High DPI
App.manifest
Add the relevant
app.manifestentries. It should roughly look like the following (You need to add some xmlns entries to the top level root element, see https://github.com/cefsharp/CefSharp/blob/cefsharp/79/CefSharp.Wpf.Example/app.manifest for a working example)Programatically
WPFapplications by default have an automatically generatedProgram.Mainentry point which makes it harder to programatically set theDPI. See https://stackoverflow.com/a/26890426/4583726 for how to create aProgram.Mainthen you can call Cef.EnableHighDPISupport();. This must be called very early on in your application execution, preferably the first call in your custom Program.Main.OffScreen High DPI
Add the relevant
app.manifestentries or callCef.EnableHighDPISupport()(see above for an example). Read theWinFormssection above, choose which option suites your needs.High DPI Additional Info
Chromiumby default performs all rendering in separate sub-process. Specifically theGPU Compositorneeds to have aDPI Awarenessthat matches your main application. Currently the default used by theCefSharp.BrowserSubprocess.exeisPer Monitor DPI Aware. As a workaround use thedisable-gpu-compositingcommand line arg and theDPI Awarenessof your main application process will be used instead of theDPI Awarenessspecified by theGPU Process(which is used forGPU Compositing). DisablingGPU Compositingmay have an impact on performance, when #2927 is complete it will be possible to programatically set theDPI Awarenessused by theCefSharp.BrowserSubprocess.exeAlternatively you can try the force-device-scale-factor command line flag.
It's a very long MSDN article, but it's necessary reading if your app needs to be run on high DPI displays.
amaitland commentedon Mar 30, 2020
The
General Usage Guidehas been updated see https://github.com/cefsharp/CefSharp/wiki/General-Usage/_compare/69741e80118da403d7c086695965427869164f1e...592d4fae743f567a30126e6f03c5f92faf9c6f59Once this feature has been complete additional details will need to be added.
cwollenhaupt commentedon Aug 31, 2021
FYI, I fixed this issue for my projects by modifying the manifest in CefSharp.BrowserSubprocess.EXE to match my main applications DPI awareness. I gave the EXE a different name and set the BrowserSubprocessPath property accordingly.
amaitland commentedon Aug 31, 2021
Be careful copying the Browsersubprocess and renaming it as I've seen previous cases where antivirus software have flagged the exe as suspicious. Much safer to create your own exe or self host the browser sub process using https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Core/BrowserSubprocess/SelfHost.cs#L22
Same code can be used to create own exe.
cwollenhaupt commentedon Sep 1, 2021
Good to know, thanks for the heads up!
amaitland commentedon Mar 7, 2023
Changes in
Chromium(#4410) mean that theBrowserandGPUprocesses will now bePerMonitorV2by default,You can override the
Chromiumdefault via setting the awareness in yourapp.manifestor programmatically.The
BrowserSubProcesswill use theChromiumdefaults starting fromM111(commit b17cd2a)The interesting side-effect of this change is that it would appear that when set programmatically then the
GPUprocess will mirror the awareness of the browser process (by default this is your application).So starting in
M111you should be able to PInvoke.SHCore the awareness in your application andChromiumshould respect your awareness. (Must be set beforeCef.Initialzeis called and before your process creates an windows/forms).Only seems to work when set programmatically. If for some reason this doesn't work then
Self HostingtheBrowserSubProcesswill allow complete control.There are new more detailed instructions at https://github.com/cefsharp/CefSharp/wiki/SelfHost-BrowserSubProcess
amaitland commentedon Mar 15, 2023
Setting
PerMonitorV2using PInvoke.User32 should look something like:davidei1955 commentedon Jun 25, 2024
FWIW, I am seeing this issue in .Net 8.0 Core Winforms on Windows 10 when the display is set to 125% (but not when set to 100%). I don't see it at all on Windows 11. The fix for me was to delete app.manifest, then recreate it in Visual Studio, and uncomment the
section in the new app.manifest. The manifest change suggested above in Section Winforms HI DPI does not appear to be supported in Core Winforms.
amaitland commentedon Jun 25, 2024
To revise this statement in the context of WinForms. Setting
DPI Awarenessviaapp.manifestis no longer recommended when using.Net 4.8or greater (this includes newer versions including.Net 8.0).See https://learn.microsoft.com/en-us/dotnet/desktop/winforms/wfdev-diagnostics/wfac010?view=netdesktop-8.0 for Microsoft guidance regarding the compiler warning that will be raised.
Starting in
.Net Core 3.0you can use the WinForms specific API. Some examples (refer to the Microsoft documentation for more details)https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.sethighdpimode?view=windowsdesktop-8.0
davidei1955 commentedon Jun 26, 2024
I was just hunting down down the compiler warning when I saw your post. Adding
Application.SetHighDpiMode(HighDpiMode.SystemAware);To my main() method also resolved the issue. Thanks for the heads-up!