C# Windows.Forms.WebBrowser 缩放 [英] C# Windows.Forms.WebBrowser scaling

查看:49
本文介绍了C# Windows.Forms.WebBrowser 缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 窗体应用程序中有一个 WebBrowser 控件,并且想要更改缩放级别"我正在加载的 HTML 页面(在我的示例中为 Bing 地图).

I have a WebBrowser control in my Windows Forms app and want to change the "zoom level" of the HTML page I am loading (in my case Bing map).

我希望找到在文档"属性级别执行此操作的方法,但没有可使用的缩放或高度/宽度/大小属性(在浏览器级别有,但我不想调整控制自己).

I expected to find ways to do this at the 'Document' property level, but there is no zoom or height/width/size property to play with (there is at the browser level but I don't want to resize the control itself).

附上我想做的事的照片.有什么想法吗?谢谢.

Attached are pics of what I want to do. Any thoughts? Thanks.

浏览器缩放问题

推荐答案

吉米基本上是对的.但我会继续给你完整的代码/解释.

Jimi is basically right. But I will go ahead and give you the full code/explanation.

您想添加对 Microsoft Internet Controls 的 COM 引用,以便您可以访问 ShDocVw.

You want to add a COM reference to Microsoft Internet Controls so you have access to ShDocVw.

using System;
using System.Windows.Forms;

namespace winforms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            webBrowser1.Navigate(new Uri("http://www.google.com"));
            webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted;
        }

        private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var browser = webBrowser1.ActiveXInstance as SHDocVw.InternetExplorer;
            browser.ExecWB(SHDocVw.OLECMDID.OLECMDID_OPTICAL_ZOOM, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT,200 ,IntPtr.Zero );
        }
    }
}

200 代表缩放级别.EG 200% 缩放.如果你做了 50% 的缩放,那就是缩小.换句话说,小于 100 的值表示缩小,大于 100 的值表示放大.可能的值范围为 10-1000.

The 200 represents the zoom level.EG 200% zoom. If you did 50% zoom, that would be zooming out.In other words values less than 100 mean zooming out, and values greater than 100 are zooming in. Possible Values range from 10-1000.

文档链接

不幸的是,许多 COM 组件是为 C++ 开发人员而不是 C# 编写的,因为 COM 是围绕二进制兼容性的 C++ 范例.因此,在 C# 中,我们可以与这些最初用 C++ 编写的 COM 对象进行互操作.

Unfortunately, many of the COM components are documented for C++ developers not C# as COM is a C++ paradigm around binary compatibility. And thus in C# we can interop with these COM objects that were originally written in C++.

关于 COM,您必须记住的另一个技巧是,每次添加新功能时,都会将其添加到新界面中.例如.IHTMLDocument2 IHTMLDocument3, IHTMLDocument4 等,所以你需要知道你真正想要投射你的 COM 的接口反对.

The other trick you have to remember about COM is that each time new functionality is added, it gets added to a new interface. E.G. IHTMLDocument2 IHTMLDocument3, IHTMLDocument4, etc. So you need to know which interface you actually want to cast your COM object to.

这篇关于C# Windows.Forms.WebBrowser 缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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