Windows窗体Web浏览器控件缩放级别 [英] Windows forms web browser control zoom level
问题描述
我正在使用Web浏览器控件在我的应用程序中显示一些即时生成的HTML文档。
I'm using a web browser control to display some on-the-fly generated HTML documents in my application.
问题是,在我的机器上说文档是放大显示。在其他同事的计算机上,一切看起来正常。它必须是某种本地设置,但我找不到在哪里更改它。
Problem is, on my machine said documents are displayed kinda zoomed in. On other colleagues' computers, everything looks "normal". It has to be some kind of local setting but I can't find where to change it.
我可以按CTRL +滚轮进行缩小,但不保留缩放级别。据我所知,没有一种简单的方法可以通过编程方式设置预定义的缩放级别。
I can CTRL + Scroll wheel to zoom out, but zoom level is not retained. As far as I can see, there's no easy way to set the predefined zoom level programmatically.
这可能是一个长镜头,但我担心它与Internet有关资源管理器(我从未使用过)及其设置。不幸的是,更改控件类型不是一个可行的选择。
It may be a long shot but I fear it has something to do with Internet Explorer (which I never use) and its settings. Changing control type is not a viable option, unfortunately.
任何帮助都将受到感激,谢谢。
Any help would really be appreciated, thank you.
推荐答案
问题是,在我的计算机上显示的文档有点放大了
。
Problem is, on my machine said documents are displayed kinda zoomed in.
Internet Explorer尊重Windows的缩放比例设置。因此,在缩放比例为100的系统上,您在 WebBrowser
控件上看到的大小不同于在 WebBrowser 上看到的大小。缩放比例为150的系统上的code>控件,而两个
WebBrowser
控件均设置为100%缩放。
Internet Explorer respects to the windows scale settings. As a result the size that you will see on WebBrowser
control on a system having scaling 100, is different from the size which you see on WebBrowser
control on a system having scaling 150, while both WebBrowser
controls set to 100% zoom.
原因是由于缩放。缩放因子与Windows缩放因子相同,除以100或 physicalScreenHeight / logicalScreenHeight
。
The reason is because of scaling. The scaling factor is same as Windows scaling factor divided by 100 or physicalScreenHeight/logicalScreenHeight
.
据我所知,没有简单的方法可以通过编程方式设置预定义的缩放
级别。
As far as I can see, there's no easy way to set the predefined zoom level programmatically.
实际上有。要更改Web浏览器控件的缩放级别,可以获取 IWebBrowser2
实例= https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.forms.webbrowserbase.activexinstance?WT.mc_id=DT-MVP-5003235&view=netframework-4.8 rel = nofollow noreferrer> WebBrowser.ActiveXInstance
属性,然后使用其 ExecWB
方法,设置这样缩放:
In fact there is. To change the zoom level of Web Browser control, you can get IWebBrowser2
instance from the WebBrowser.ActiveXInstance
property and then using its ExecWB
method, set set the zoom this way:
int OLECMDID_OPTICAL_ZOOM = 63;
int OLECMDEXECOPT_DONTPROMPTUSER = 2;
dynamic iwb2 = webBrowser1.ActiveXInstance;
object zoom = 200; //The value should be between 10 , 1000
iwb2.ExecWB(OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, zoom, zoom);
您还可以添加对 Microsoft Internet Controls(SHDocVw.dll)的引用
并将 WebBrowser.ActiveXInstance
转换为 SHDocVw.WebBrowser
并使用 ExecWB
方法。但是上面的代码无需添加任何引用即可达到目的。
You can also add reference to Microsoft Internet Controls (SHDocVw.dll)
and cast WebBrowser.ActiveXInstance
to SHDocVw.WebBrowser
and use ExecWB
method. But above code does the trick without adding any reference.
Web浏览器缩放与CSS3缩放完全不同。但是您可能想知道如何设置文档正文缩放: webBrowser1.Document.Body.Style = zoom:200%;
Web browser zoom is completely different from CSS3 zoom. But you may want to know about how to set document body zoom: webBrowser1.Document.Body.Style = "zoom:200%";
以上所有代码应在文档完成后运行。
All above codes should be run after document has been completed.
这篇关于Windows窗体Web浏览器控件缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!