WPF web浏览器 - 如何放大内容? [英] WPF WebBrowser - How to Zoom Content?

查看:159
本文介绍了WPF web浏览器 - 如何放大内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想测试一个WPF基本的浏览器概念(C#/ XAML,.NET 4.0)web浏览器的应用程序。到目前为止,唯一的问题是编程变焦。有没有人有这样的经验吗?

Trying to test basic browser concepts in a WPF (C#/XAML, .NET 4.0) WebBrowser application. So far, the only problem is programatically zooming. Has anyone had any experience with this?

MSDN列出什么:的http:// MSDN。 microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx 此外,我曾尝试过各种事情,如的RenderTransform选择无济于事。无论这是不可能的,或没有记录。我希望后者。请注意,一个WinForm溶液是不能接受的。

MSDN lists nothing: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx Additionally, I have tried various things such as RenderTransform options to no avail. Either this is not possible or not documented. I'm hoping for the latter. Note that a WinForm solution isn't acceptable.

在此先感谢您的帮助, Beems

Thanks in advance for any help, Beems

推荐答案

也许你可以这样执行的JavaScript。

Maybe you can execute a javascript like this.

document.body.style.zoom = 1.5;

在WPF中我们可以操纵文档。我创建了一个扩展方法为你,这样你就可以设置缩放:

In WPF we can manipulate the document. I Created a Extension Method for you, so you can set the Zoom:

// www.tonysistemas.com.br
public static partial class MyExtensions
{
    public static void SetZoom(this System.Windows.Controls.WebBrowser WebBrowser1, double Zoom)
    {
        // For this code to work: add the Microsoft.mshtml .NET reference      
        mshtml.IHTMLDocument2 doc = WebBrowser1.Document as mshtml.IHTMLDocument2;
        doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";");
    }
}

用法:

WebBrowser1.SetZoom(0.5);

这篇关于WPF web浏览器 - 如何放大内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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