WPF Web浏览器控件和DPI缩放 [英] WPF Web Browser Control and DPI Scaling

查看:173
本文介绍了WPF Web浏览器控件和DPI缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用使用Web浏览器控件的WPF应用程序,但在DPI缩放比例过高时遇到问题。

I'm working with a WPF application that uses the Web Browser control and I'm having issues with High DPI scaling.

似乎Web浏览器控件未正确遵守系统的DPI设置,而WPF应用程序的其余部分正在正确缩放UI。这意味着在更高级别上,WPF界面会变大,而Web浏览器内容仍保持原始,现在看起来更小。

It looks like the Web Browser control is not properly respecting the DPI settings of the system, while the rest of the WPF application is properly scaling the UI. This means that on higher scale levels the WPF interface gets larger while the Web browser content stays on the original, now smaller looking size.

下面是从使用两个Web浏览器控件的WPF应用。

Here's an example of screen captures from a WPF app that uses two Web Browser Controls.

100%缩放:

150%缩放比例:

相对于主要表单内容(工具栏/菜单/状态栏),第二个图像中的Web浏览器缩放比例要比第一个图像小得多。

Notice in the second image the Web Browser scaling is much smaller than in the first picture relative to the main form content (toolbar/menu/statusbar).

是否有某种方法可以强制Web浏览器控件正确使用从应用程序继承的High DPI设置?

Is there some way to force the Web Browser control to properly use High DPI settings inherited from the application?

此MSDN链接:
< a href = https://msdn.microsoft.com/en-us/library/mt622670.aspx rel = noreferrer>解决DPI问题

显示了一种非常底层的方法(在文档底部),实现了自定义Web浏览器COM界面,但是我想知道是否可能有一种更干净的方法来解决此问题。

shows a really low level approach (at the bottom of doc) implementing custom Web browser COM interfaces, but I'm wondering if there might be a cleaner way to address this.

推荐答案

我发现我认为是实现所需功能的最佳方法(提供的,无论如何,您都需要指定 FEATURE_BROWSER_EMULATION 在注册表中使用最新的IE版本)

I have found what I think is the best way to achieve the required functionality (provided, that you anyway need to specify FEATURE_BROWSER_EMULATION in registry to use most recent IE version).

您需要做的就是在<$ c $中创建一个新密钥。 c>名为 FEATURE_96DPI_PIXEL 的HKCU\软件\Microsoft\Internet Explorer\Main\FeatureControl ,并在其中添加类型为 DWORD(32位),其中应用程序exe为键名,值 1

All you need to do, is to create a new key in HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl named FEATURE_96DPI_PIXEL and add your executable entry there of type DWORD (32-bit), with application exe as a key name and value of 1.

在实际实例化WebBrowser组件之前,请检查应用程序启动时的设置。 d您应该没事。

Check the setting on startup of the application, before actually instantiating the WebBrowser component and you should be fine.

原始帖子(具有其他可能的功能):
https://www.reddit.com/r/dotnet/comments/2j5m6m/wpf_webbrowser_control_alternatives/

Original post (with other possible features): https://www.reddit.com/r/dotnet/comments/2j5m6m/wpf_webbrowser_control_alternatives/

这篇关于WPF Web浏览器控件和DPI缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆