Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

xaml - WPF WebBrowser - How to Zoom Content?

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 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.

Thanks in advance for any help, Beems

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe you can execute a javascript like this.

document.body.style.zoom = 1.5;

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(",", ".") + ";");
    }
}

Usage:

WebBrowser1.SetZoom(0.5);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...