Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You might want to use the WebBrowser control and extend it using the example provided here: <a href="http://www.codeproject.com/KB/miscctrl/wbp.aspx" rel="noreferrer">http://www.codeproject.com/KB/miscctrl/wbp.aspx</a></p> <p>[<strong>Edit:</strong> updated the answer to illustrate how to accomplish the same using the WPF WebBrowser control (System.Windows.Controls.WebBrowser)]</p> <p>The underlying control is the same - it's the ActiveX component in SHDocVw.dll.</p> <p>I pulled together some better reference URL's for you. Turns out there's a pretty good lead on doing something similar from the MSDN documentation for the control: <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser(v=vs.90).aspx#4" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser(v=vs.90).aspx#4</a> There's also this: <a href="http://support.microsoft.com/kb/329014" rel="noreferrer">http://support.microsoft.com/kb/329014</a>. </p> <p>You'll need to add a reference to SHDocVw, which is under the COM reference list as "Microsoft Internet Controls"</p> <pre><code>[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("6d5140c1-7436-11ce-8034-00aa006009fa")] internal interface IServiceProvider { [return: MarshalAs(UnmanagedType.IUnknown)] object QueryService(ref Guid guidService, ref Guid riid); } static readonly Guid SID_SWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046"); void webBrowser_LoadCompleted(object sender, NavigationEventArgs e) { IServiceProvider serviceProvider = null; if (webBrowser.Document != null) { serviceProvider = (IServiceProvider)webBrowser.Document; } Guid serviceGuid = SID_SWebBrowserApp; Guid iid = typeof(SHDocVw.IWebBrowser2).GUID; object NullValue = null; SHDocVw.IWebBrowser2 target = (SHDocVw.IWebBrowser2)serviceProvider.QueryService(ref serviceGuid, ref iid); target.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, ref NullValue, ref NullValue); } </code></pre> <p>XAML:</p> <pre><code>&lt;Window x:Class="StackOverflowWPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"&gt; &lt;Grid&gt; &lt;DockPanel LastChildFill="True"&gt; &lt;WebBrowser Name="webBrowser" Source="http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx" LoadCompleted="webBrowser_LoadCompleted"&gt; &lt;/WebBrowser&gt; &lt;/DockPanel&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Anyone interested in the WinForms control version (System.Windows.Forms.WebBrowser) can skip all the IServiceProvider baggage and just use the ActiveXInstance property (which the WPF control doesn't expose:</p> <pre><code>SHDocVw.WebBrowser target = webBrowser.ActiveXInstance as SHDocVw.WebBrowser; target.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, null, null); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload