WPF Web浏览器控件和DPI缩放

编程入门 行业动态 更新时间:2024-10-28 10:23:23
本文介绍了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链接: 解决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).

您需要做的就是在名为 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.

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

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

更多推荐

WPF Web浏览器控件和DPI缩放

本文发布于:2023-11-09 16:14:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   控件   浏览器   WPF   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!