Winforms WebBrowser control
I've been playing around with the WinForms WebBrowser control this morning, and after lots of experimentation have finally figured out how to use some of the printing functionality.
First of all, Add a Reference to SHDocVw. (Project > Add Reference > Browse > C:\Windows\System32\shdocvw.dll)
Secondly load a document into the browser using webBrowser1.Navigate(url).
Then,
to do "Print Preview"...
[color="#teal"]IWebBrowser2 [/color]browser = ([color="teal"]IWebBrowser2[/color])webBrowser1.ActiveXInstance; [color="blue"]object [/color]pvaIn = [color="teal"]Missing[/color].Value; [color="blue"]object [/color]pvaOut = [color="teal"]Missing[/color].Value; browser.ExecWB([color="teal"]OLECMDID[/color].OLECMDID_PRINTPREVIEW, [color="teal"]OLECMDEXECOPT[/color].OLECMDEXECOPT_DODEFAULT, [color="blue"]ref [/color]pvaIn, [color="blue"]ref [/color]pvaOut);
To show the "Page Setup" dialog...
[color="#teal"]IWebBrowser2 [/color]browser = ([color="teal"]IWebBrowser2[/color])webBrowser1.ActiveXInstance; [color="blue"]object [/color]pvaIn = [color="teal"]Missing[/color].Value; [color="blue"]object [/color]pvaOut = [color="teal"]Missing[/color].Value; browser.ExecWB([color="teal"]OLECMDID[/color].OLECMDID_PAGESETUP, [color="teal"]OLECMDEXECOPT[/color].OLECMDEXECOPT_DODEFAULT, [color="blue"]ref [/color]pvaIn, [color="blue"]ref [/color]pvaOut);
To Print straight away, without prompting the user:
[color="#teal"]IWebBrowser2 [/color]browser = ([color="teal"]IWebBrowser2[/color])webBrowser1.ActiveXInstance; [color="blue"]object [/color]pvaIn = [color="teal"]Missing[/color].Value; [color="blue"]object [/color]pvaOut = [color="teal"]Missing[/color].Value; browser.ExecWB([color="teal"]OLECMDID[/color].OLECMDID_PRINT, [color="teal"]OLECMDEXECOPT[/color].OLECMDEXECOPT_DONTPROMPTUSER, [color="blue"]ref [/color]pvaIn, [color="blue"]ref [/color]pvaOut);
(The first three lines are same every time, it's only the last line that's different).

0 Comments
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now