WPF Webbrowser 如何缩小页面加载事件?
WPF Webbrowser How do I zoom out on Page loaded event?
这个事件处理程序returns:
System.Runtime.InteropServices.COMException: 'Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))'
代码:
private void Browser_Loaded(object sender, NavigationEventArgs e)
{
browser.InvokeScript("Document.Body.Style =" + "zoom:80%");
}
我尝试了很多网上找到的解决方案,但 none 似乎对我有用
请指教
试试这个
private void Browser_Loaded(object sender, NavigationEventArgs e)
{
var zoom = 0.8;
mshtml.IHTMLDocument2 doc = browser.Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("document.body.style.zoom=" + zoom.ToString().Replace(",", ".") + ";");
}
它对我有用。
别忘了参考Microsoft.mshtml
参考文献:
- WPF WebBrowser - How to Zoom Content?
- Zoom WPF-WebBrowser-Control Content
这个事件处理程序returns:
System.Runtime.InteropServices.COMException: 'Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))'
代码:
private void Browser_Loaded(object sender, NavigationEventArgs e)
{
browser.InvokeScript("Document.Body.Style =" + "zoom:80%");
}
我尝试了很多网上找到的解决方案,但 none 似乎对我有用 请指教
试试这个
private void Browser_Loaded(object sender, NavigationEventArgs e)
{
var zoom = 0.8;
mshtml.IHTMLDocument2 doc = browser.Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("document.body.style.zoom=" + zoom.ToString().Replace(",", ".") + ";");
}
它对我有用。
别忘了参考Microsoft.mshtml
参考文献:
- WPF WebBrowser - How to Zoom Content?
- Zoom WPF-WebBrowser-Control Content