首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Print WebBrowser control

Posted on 2005-03-31 11:37  delphi  阅读(399)  评论(0)    收藏  举报
To print Webbrowser control use any of these three options.

1. Sending ^p key, using SendKeys, which is not really clean programming

2. Using the shell command, and rundll32

Shell "rundll32.exe C:\WINDOWS\SYSTEM\MSHTML.DLL,PrintHTML " & _ "http://www.yahoo.com" , vbMinimizedFocus

3. Finally, method 3, this will be a best method, and uses the built-in commands for the web-browser.

Private Sub PrintHtmlPage()
'first navigate to the HTML Page
'if you want to print current HTML no need to navigate
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