Method |
Description |
Goback |
EquivalentIE"Back"Button to remove |
Goforward |
EquivalentIE"Forward"Button to forward an item in the Current History List |
Gohome |
EquivalentIE"Home Page"Button to connect to the user's default home page |
Gosearch |
EquivalentIE"Search"Button to connect to the user's default search page |
Navigate |
Connect to the specifiedURL |
Refresh |
Refresh current page |
Refresh2 |
Same as above, but the refresh level can be specified. The value of the specified refresh level comes fromRefreshconstantsEnumeration table, This table is defined inExdisp. hYou can specify the following values: Refresh_normalDo not send HTTP Pragma: No-Cache hair to the server. Refresh_ifexpiredSimple refresh is performed only after the webpage expires. Refresh_continueFor internal use only. InMsdnIt saysDo not use! Do not use Refresh_completelySend requests containing the Pragma: No-Cache header to the server |
Stop |
EquivalentIE"Stop"Button to stop loading the current page and its content |
Attribute |
Description |
Application |
If the object is validWebbrowserThe Automation Object implemented by the application of the control (Idispatch). If the automation object in the Host object is invalid, this program will returnWebbrowser Control Automation Object |
Parent |
ReturnWebbrowserThe parent Automation Object of the control, usually a container, such as a host orIEWindow |
Container |
ReturnWebbrowserThe Automation Object of the control container. Generally, this value correspondsParentThe value returned by the property is the same. |
Document |
Returns an automated object for the active document. IfHtmlCurrently being displayed inWebbrowser, Then DocumentAttributeDHTML Object ModelAccess path |
Toplevelcontainer |
ReturnsBooleanValue, indicatingIEIs itWebbrowserControl top-level container.True |
Type |
ReturnedWebbrowserType of the object loaded by the control. For example, if you load. DocFile, it will return BackMicrosoft Word Document |
Left |
Return or setWebbrowserThe distance between the left side of the control window and the left side of the container window |
Top |
Return or setWebbrowserDistance between the left side of the control window and the top side of the container window |
Width |
Return or setWebbrowserThe window width, in pixels. |
Height |
Return or setWebbrowserThe height of the window, in pixels. |
Locationname |
Returns a string containingWebbrowserThe name of the currently displayed resource. If the resource A webpage is the title of a webpage. A file or folder is the name of a file or folder. |
Locationurl |
ReturnWebbrowserTheURL |
Busy |
ReturnsBooleanValue, descriptionWebbrowserCurrent loading?URLIfTrue You can useStopTo cancel the ongoing access operation. |
Webbrowser events
Private events |
Description |
Beforenavigate2 |
Triggered before navigation, not refreshed |
Commandstatechange |
It is triggered when the activation status of the command changes. It indicates when to activate or disableBackAndForward Menu item or button |
Documentcomplete |
When the entire document is completed, refresh the page without triggering |
Downloadbegin |
This event can also be triggered when a download operation is started and refreshed. |
Downloadcomplete |
This event can also be triggered when a download operation is completed and refreshed. |
Navigatecomplete2 |
Triggered after navigation, not refreshed |
Newwindow2 |
Triggered before creating a new window |
Onfullscreen |
WhenFullscreenTriggered when the attribute is changed. This event usesVarient_boolA loss Input parameters to indicateIEIs the full screen display mode (Varient_true) Or normal display mode (Varient_false) |
Onmenubar |
ChangeMenubarWhen the attribute is triggered, the parameter isVarient_boolType. Variant_trueIs visible,Variant _ falseYes hide |
Onquit |
Whether the user closes the browser or the developer callsQuitMethod, whenIEIt will be triggered when you exit |
Onstatusbar |
AndOnmenubarThe same call method indicates whether the status bar is visible. |
Ontoolbar |
The call method is the same as the preceding one, indicating whether the toolbar is visible. |
Onvisible |
The control window is visible or hidden.Varient_boolType Parameters |
Statustextchange |
If you want to change the text in the status bar, this event will be triggered, but it does not care whether the program has the status bar |
Titlechange |
Triggered when title is valid or changed |
Tips
1. Right-click Disabled
I have seen a lot of questions about the webbrowser control prohibiting right-clicking, and there are many methods to reply to them. I have mentioned using the webbrowser provided by Microsoft to extend the COM Server Object (wbcustomizer. DLL), but this method has many drawbacks when we want to use webbrowser to edit the webpage (webbrowser1.document.exe ccommand "editmode"), for example, the selected text cannot be displayed. In addition, some methods do not need to be listed one by one.
What I want to mention here is about mshtml. htmldocument
Reference Microsoft HTML Object Library
Rem # form code #
Dim withevents m_dom as mshtml. htmldocument
Private function m_dom_oncontextmenu () as Boolean
M_dom_oncontextmenu = false
End Function
Private sub webbrowser1_downloadcomplete ()
Set m_dom = webbrowser1.document
End sub
Rem okay, right-click the menu and no more
========================================================== ======================================
2. Call the control and get it from the favorites folder.
Basically, you can get the path of the favorites folder by using specialfolder (6). Then you can use dir to read each directory cyclically, and then the file in Dir, the file name is the name you want to add to favorites. The path can be obtained by yourself based on the Path obtained above.
If you do not need Dir, you can also use the Dir control of VB.
Private type shitemid
CB as long
Abid as byte
End type
Public type itemidlist
Mkid as shitemid
End type
Public Function specialfolder (byref csidl as long) as string
'Locate the favorites folder
Dim R as long
Dim Spath as string
Dim IDL as itemidlist
Const noerror = 0
Const max_length = 260
R = shgetspecialfolderlocation (mdimain. hwnd, csidl, IDL)
If R = noerror then
Spath = space $ (max_length)
R = shgetpathfromidlist (byval IDL. mkid. CB, byval Spath)
If r then
Specialfolder = left $ (Spath, instr (Spath, vbnullchar)-1)
End if
End if
End Function
========================================================== ==================================
3. Full Screen
Yes, webbrowser is a control. You want it to be full screen, that is, the full screen of its form. You can use setwindowlong to cancel the title of the form and call showwindow (findwindow ("shell_traywnd ", ""), 0) Hide tray, that is, the line containing the start line below. use call showwindow (findwindow ("shell_traywnd", ""), 9) to restore. enough details.
Then in form1.windowstate = 2.
========================================================== ==========================================================
4. Select the content on the webpage.
Private sub commandementclick ()
'Select some content first
Me. webbrowser1.execwb olecmdid_copy, olecmdexecopt_dodefault
Msgbox clipboard. gettext
End sub
========================================================== ========================================
5. Use IE to download files
Private declare function dofiledownload lib "shdocvw. dll" (byval lpszfile as string) as long
Private sub commandementclick ()
Dim sdownload as string
Sdownload = strconv (text1.text, vbunicode)
Call dofiledownload (sdownload)
End sub
Private sub form_load ()
Text1.text = "http://www.chat.ru /~ Softdaily/fo-ag162.zip"
Form1.caption = "audiograbber 1.62 full"
Text2.text = "http://www6.50megs.com/audiograbber/demos/cr-ag161.zip"
End sub
========================================================== ====================================
6. How should I dynamically load and delete the webbrowser control?
Private sub commandementclick ()
Form1.controls. Add "shell. assumer.2", "newweb", form1
With form1! Newweb
. Visible = true
. Width = 10000
. Height = 10000
. Left = 0
. Top = 0
. Navigate2 "http://www.csdn.net /"
End
End sub
Private sub command2_click ()
Controls. Remove form1! Newweb
End sub
Form1.controls. Add "shell. assumer.2", newweb (newweb. Count), form1
With form1! Newweb (newweb. Count)
. Visible = true
. Width = 1000
. Height = 1000
. Left = newweb (newweb. Count-1). Left + newweb (newweb. Count-1). Width
. Top = 0
'. Navigate2 "http://www.csdn.net /"
End
Why did he say "I "?
Form1.controls. Add "shell. assumer.2", newweb (newweb. Count), form1
This row is of error 13 Type mismatch?
PS: I already have a newweb (0) Control in form.
First for a webbrowser
Dim I as integer
Private sub addweb_click ()
For I = 1 to 10
Load newweb (I)
Newweb (I). Top = I * 100
Newweb (I). Left = I * 100
Newweb (I). Visible = true
Next I
End sub
Private sub delweb_click ()
For I = 1 to 10
Unload newweb (I)
Next I
End sub
========================================================== ====================
7. Save the page as an MHT (MHTML) File
The pcwak (ShuJian mad life [ms mvp]) provided by the documents, for your reference:
I finally found a method to save the page as a MHT (MHTML) file!
First, you must reference a library in the project:
Library CDO
D: \ winnt \ system32 \ cdosys. dll
Microsoft CDO for Windows 2000 Library
Second, you need to support the corresponding stream interface. If you cannot find it at the moment, you can use the newer ado that supports it, as shown in figure
Library ADODB
D: \ Program Files \ common files \ System \ ADO \ msado15.dll
Microsoft ActiveX Data Objects 2.5 Library
The Code is as follows, which is very simple (due to the characteristics of the stream, in actual applications, it is not necessary to save the file to the disk as in this example to directly convert it into a string or byte array or something.
In addition, I have not tried how to use the Microsoft CDO for Windows 2000 library in Win98. If you are interested, try and follow the instructions to enrich the content :)
Private sub commandementclick ()
'Reference to Microsoft ActiveX Data Objects 2.5 Library
'Reference to Microsoft CDO for Windows 2000 Library
Dim imsg as new CDO. Message
Dim iconf as new CDO. Configuration
Dim objstream as ADODB. Stream
With imsg
. Createmhtmlbody "http://www.163.com /";,,_
"Domain \ Username ",_
"Password"
Set objstream =. getstream
Call objstream. savetofile ("F: \ test. MHT", adsavecreateoverwrite)
End
End sub
2,
'First Add a reference to ADODB and CDO (Microsoft CDO for Windows 2000 library, corresponding to the file name cdosys. dll)
Private sub commandementclick ()
Dim message as new CDO. Message
Dim outstream as ADODB. Stream
On Error goto myerr1
Call message. createmhtmlbody ("http://www.csdn.net/", CDO. cdomhtmlflags. cdosuppressnone ,"","")
Set outstream = message. getstream
Call outstream. savetofile ("C: \ test. MHT", ADODB. saveoptionsenum. adsavecreateoverwrite)
Msgbox "complete"
Exit sub
Myerr1:
Set message = nothing
Set outstream = nothing
End sub
========================================================== ====================
8. Use the webbrowser control to call favorites and add favorites to favorites.
Option explicit
Private sub commandementclick ()
Dim objsuh as new shelluihelper
Objsuh. AddFavorite "http://www.csdn.net/", "csdn"
Set objsuh = nothing
End sub
========================================================== ========================
9. How to Prevent the webpage from having a scroll bar:
Private sub mnuscroll1_click ()
'Note: The operation can only be performed after the webpage is fully displayed.
Webbrowser1.document. Body. Scroll = "no "'.
End sub
Private sub mnuscroll2_click ()
'Note: The operation can only be performed after the webpage is fully displayed.
Webbrowser1.document. Body. Scroll = "Auto" ': how to display a scroll bar
End sub
========================================================== ======================================
10. How to obtain the HTML of the selected part of the webpage:
Private sub commandementclick ()
Dim objselection
Dim objtxtrange
Set objselection = webbrowser1.document. Selection
If not (objselection is nothing) then
Set objtxtrange = objselection. createRange
If not (objtxtrange is nothing) then
Debug. Print objtxtrange.html text
Set objtxtrange = nothing
End if
Set objselection = nothing
End if
End sub
Private sub form_load ()
Web Browser "http://www.applevb.com /"
End sub
11. Page scrolling:
Private sub command2_click ()
Webbrowser1.document. parentwindow. scrollby 0, 30
End sub
Private sub form_load ()
Webbrowser1.navigate "http://www.applevb.com"
End sub
Click command2 to scroll down the current page by 30 pixels
12. Determine whether the page can be moved forward and backward
Private sub commandementclick ()
Webbrowser1.goforward
End sub
Private sub command2_click ()
Webbrowser1.goback
End sub
Private sub form_load ()
Webbrowser1.navigate "http://www.applevb.com"
End sub
Private sub webbrowser1_commandstatechange (byval command as long, byval enable as Boolean)
If (command = csc_navigateback) then
Command2.enabled = Enable
End if
If (command = csc_navigateforward) then
Command1.enabled = Enable
End if
End sub 1, add the webbrowser1 Control
Procedure tform1.formactivate (Sender: tobject );
Begin
Webbrowser1.navigate ('www .bitmodel.cn/yy ');
End;
Change the fixed window size to bssingle in borderstyle of form1.
To disable a scroll bar, you can use either of the following methods:
1. Use the documentcomplete event of webbrowser1
Procedure tform1.documentcomplete (Sender: tobject; const Pdisp: idispatch;
VaR URL: olevariant );
Begin
If assigned (webbrowser1.document) Then webbrowser1.oleobject. Document. Body. Scroll: = 'no ';
End;
2. If you can modify the embedded page, add <body scroll = NO> to the embedded page.