【发布时间】:2016-06-17 12:41:46
【问题描述】:
如果我使用 WPF 语法:
<WebBrowser Grid.Row="1" Grid.Column="1" x:Name="htmlView"></WebBrowser>
或者如果我添加一个WindowsFormsHost:
<WindowsFormsHost x:Name="formsHost" Grid.Row="1" Grid.Column="1">
</WindowsFormsHost>
在 CS 文件中:
public partial class MainWindow : Window
{
System.Windows.Forms.WebBrowser htmlView= new System.Windows.Forms.WebBrowser();
public MainWindow()
{
InitializeComponent();
formsHost.Child = htmlView;
htmlView.Navigate("d:\\test.xml");
}
private void menuFilePageSetup_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Do do");
}
}
无论哪种方式,ExecWB 方法都不会暴露。所以我不能从我的 MFC C++ CHtmlView 派生类移植这段代码:
ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
我错过了什么吗?目前我无法实现打印预览/页面设置/缩放功能,因为我无法使用ExecWB。
我已尝试从 Winforms 浏览器派生我自己的类,但仍未列出。
谢谢。
我不明白为什么在这个问题中:
How do I programmatically change printer settings with the WebBrowser control?
它指的是ShowPrintDialog,但即使它也没有列出。
部分成功!我不知道为什么,但是现在,当我使用托管的 Winforms 版本时,我至少可以看到一些方法:
public partial class MainWindow : Window
{
System.Windows.Forms.WebBrowser htmlView= new System.Windows.Forms.WebBrowser();
public MainWindow()
{
InitializeComponent();
formsHost.Child = htmlView;
htmlView.Navigate("d:\\test.xml");
}
private void menuFilePageSetup_Click(object sender, RoutedEventArgs e)
{
htmlView.ShowPageSetupDialog();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
htmlView.ShowPrintPreviewDialog();
}
}
但是ExecWb 仍然缺少用于管理缩放等操作。我发现了这个:
How do I print from the wpf WebBrowser available in .net 3.5 SP1?
答案之一:
mshtml.IHTMLDocument2 doc = webBrowser.Document as mshtml.IHTMLDocument2; doc.execCommand("Print", true, null);
但即使我添加了对 mshtml 库的引用,编译器也不会让我从 HtmlDocument 转换为 IHtmlDocument2。最终我得到了这个:
Clearing the selection in a webbrowser control
所以现在我知道如何全选并再次复制到剪贴板(只要我使用 Winforms 版本)。但是,看过这里:
https://msdn.microsoft.com/en-us/library/ms533049(v=vs.85).aspx
似乎不适合光学变焦:
ExecWB(OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, &vZoom, NULL);
【问题讨论】: