Step-by-Step Example
Create a new Standard EXE project in Visual Basic. Form1 is created by default.
Select Components from the Project menu. Add a reference to the "Microsoft Internet Controls."
Add the following controls to Form1: 1 CommandButton
1 Web Browser
Add the following code to Form1: Option Explicit Private Sub Command1_Click() ' print the contents of the Web Browser control.
WebBrowser1.ExecWB _
OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0 End Sub Private Sub Form_Load() ' set the caption of the command button.
Command1.Caption = "&Print" ' position the print command button at the top-left.
Command1.Move 0, 0 ' position the Web Browser control below the command button.
WebBrowser1.Move 0, 750 ' navigate to a Web site for testing purposes.
WebBrowser1.Navigate "http://www.microsoft.com" End Sub Private Sub Form_Resize() ' when the form is resized, the Web Browser control should
' remain the same size as the form.
WebBrowser1.Width = Form1.Width
WebBrowser1.Height = Form1.Height End Sub
Press the F5 key to run the project. When the test site has been downloaded and rendered in the Web Browser, click the "Print" command button, and the contents of the Web Browser will be printed. NOTE: Using version 3.x of the Web Browser control will result in a Print Dialog appearing when you attempt to print the content of the control. This is by design.
Create a new Standard EXE project in Visual Basic. Form1 is created by default.
Select Components from the Project menu. Add a reference to the "Microsoft Internet Controls."
Add the following controls to Form1: 1 CommandButton
1 Web Browser
Add the following code to Form1: Option Explicit Private Sub Command1_Click() ' print the contents of the Web Browser control.
WebBrowser1.ExecWB _
OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0 End Sub Private Sub Form_Load() ' set the caption of the command button.
Command1.Caption = "&Print" ' position the print command button at the top-left.
Command1.Move 0, 0 ' position the Web Browser control below the command button.
WebBrowser1.Move 0, 750 ' navigate to a Web site for testing purposes.
WebBrowser1.Navigate "http://www.microsoft.com" End Sub Private Sub Form_Resize() ' when the form is resized, the Web Browser control should
' remain the same size as the form.
WebBrowser1.Width = Form1.Width
WebBrowser1.Height = Form1.Height End Sub
Press the F5 key to run the project. When the test site has been downloaded and rendered in the Web Browser, click the "Print" command button, and the contents of the Web Browser will be printed. NOTE: Using version 3.x of the Web Browser control will result in a Print Dialog appearing when you attempt to print the content of the control. This is by design.
我明白了
:)
收分请