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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -681,35 +681,87 @@ If you need better printing support then you should discuss that on `ceforum`. T
## High DPI Displays/Support
To enable _High DPI_ support you'll need to add the relevant entries to your `app.manifest` to let Windows know your app is _High DPI Aware_. The relevant MSDN article is https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx it's also recommended that you read https://docs.microsoft.com/en-us/windows/desktop/sbscs/application-manifests for details on how to set the entries in the `app.manifest`
Desktop applications using `WinForms/WPF`need to be made [DPI Aware](https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows) to run correctly on a _High DPI Display_ (A display with a `DPI Scale` set greater than `100%`).
It's a very long MSDN article, but it's necessary reading if your app needs to be run on high DPI displays.
**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.
**Note** If you experience black boxes with rendering/resizing then your app likely needs changes to support `High DPI`
There are two main methods to specify the default DPI awareness of a process:
Prevent browser from scaling on High DPI use `settings.CefCommandLineArgs.Add("force-device-scale-factor", "1");` command line flag.
1.[Through an application manifest setting](https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process#setting-default-awareness-with-the-application-manifest) (This is generally the preferred option)
2.[Programmatically through an API call](https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process#setting-default-awareness-programmatically)
### WinForms
### WinForms High DPI
Add the relevant `app.manifest` entries and call `Cef.EnableHighDPISupport()`. It's best make that the first call in your application entry point.
#### App.manifest
Set the default awareness using the [application manifest](https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process#setting-default-awareness-with-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 Awareness` options
The commit where support was added to the `CefSharp.MinimalExample.WinForms` project is https://github.com/cefsharp/CefSharp.MinimalExample/commit/1197f37035549ad98c7682399c12e40be677426a. Check it out for a working example.
Setting High DPI in code you can use the [Cef.EnableHighDPISupport();](http://cefsharp.github.io/api/79.1.x/html/M_CefSharp_Cef_EnableHighDPISupport.htm) helper method. This calls the `Chromium`[base::win::EnableHighDPISupport();](https://cs.chromium.org/search/?q=EnableHighDPISupport()&sq=package:chromium&type=cs) function. You then have exactly the same settings as `Chromium` uses.
[Cef.EnableHighDPISupport();](http://cefsharp.github.io/api/79.1.x/html/M_CefSharp_Cef_EnableHighDPISupport.htm)**must** be called very early on in your application execution, preferably in your application entry point (Program.Main).
The [CefSharp.MinimalExample.WinForms](https://github.com/cefsharp/CefSharp.MinimalExample/tree/master/CefSharp.MinimalExample.WinForms) project contains a working example.
### WPF High DPI
#### App.manifest
Add the relevant `app.manifest` entries. 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)
Add the relevant `app.manifest` entries. 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/63/CefSharp.Wpf.Example/app.manifest for a working example)
`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();](http://cefsharp.github.io/api/79.1.x/html/M_CefSharp_Cef_EnableHighDPISupport.htm). 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 https://github.com/cefsharp/CefSharp/issues/2927 is complete it will be possible to programatically set the `DPI Awareness` used by the `CefSharp.BrowserSubprocess.exe`
Alternatively you can try the [force-device-scale-factor](https://peter.sh/experiments/chromium-command-line-switches/#force-device-scale-factor) command line flag.