问题描述
尝试在 WPF(C#/XAML、.NET 4.0)WebBrowser 应用程序中测试基本浏览器概念.到目前为止,唯一的问题是以编程方式缩放.有没有人有这方面的经验?
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.aspxAdditionally, 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
推荐答案
也许你可以像这样执行 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 WebBrowser - 如何缩放内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!