Library code snippets
Printing from the WebBrowser control
There are three methods for doing this.
1. Sending ^p key, using SendKeys, which is not really clean programming :P
2. Using the shell command, and rundll32
Shell "rundll32.exe C:\WINDOWS\SYSTEM\MSHTML.DLL,PrintHTML " & _ "http://www.developerfusion.com"
, vbMinimizedFocus
3. Finally, method 3, which I think is the best method, and uses the built-in
commands for the web-browser. Private Sub PrintUserPage()
'navigate to the page you want
'you can delete this if you want to print the current page
WebBrowser1.Navigate ("http://www.developerfusion.com/")
DoEvents
'print
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
'you can change OLECMDEXECOPT_DONTPROMPTUSER to OLECMDEXECOPT_PROMPTUSER if you
wish
End Sub
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
hy,
i want so set the focus to a frame..
what should i enter instead of <content> ? the frame name?
whats about iframes?
thanks
webBrowser1.ShowPrintDialog()
webBrowser1.ShowPrintDialog()
How can I print from WebBrower using other printer than default printer
That 3rd suggestion of yours worked like a charm! Thank you.
However, now I've managed to show a page in the WebBrowser that has some positioned DIVs. Their positions are changed with a JavaScript function that runs when the page loads.
And then I tried to print that layout and what got printed was the original layout, not the one shown in the WebBrowser. Out of curiosity I right-clicked the page and printed it using the command in the context menu and..... it worked.
Have you ever tried this?
Thank you in advance.
Private Sub PrintUserPage
Webbrowser1.Navigate ("http://www.yourfavouriteURL.com")
End Sub
Private Sub WebBrowser1_DownloadComplete()
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End Sub
This looks like the solution I have been looking for. But unfortunately, the shelling option doesn't print... (not sure why), but how do I code this into a VB.NET web page?
Thanks
With reference to printing the webbrowser content. Sometimes you will have just one frame that you wish to print! So you need to know the frame and set the focus to that frame!
WebBrowser1.Document.parentWindow.<content>.focus
WebBrowser1.ExecWB OLECMDIDPRINT, OLECMDEXECOPTDONTPROMPTUSER
This thread is for discussions of Printing from the WebBrowser control.