2. Designing a browser with a WebBrowser control Design a webbrowser control to design a browser relative to the front method, the specific operation should be more, because each control is set to set the properties and write the corresponding code, so that the program is relatively large. some. The methods and steps are described below in detail below. (1) Creating a new project and open a new form FORM1; (2) Right-click the toolbox to add a new component Microsoft Common Dialog Controls, Microsoft Windows Common Controls 5.0 and Microsoft Internet Controls; (3) on the window Add a Toolbar Control Toolbar1 in Form1, then open the Properties page of the Toolbar1 control, click the Insert Button button in the Button tab, add back (backward), forward (forward), STOP (stop ), Refresh, Home (Open), Search (Search), Open, NaviGate, EXIT (4) Add an ImageList Control IMAGELIST1 to Form1 Open the Properties page of the ImageList1 control, click the Insert Picture button in the Image (Image "tab, enter some appropriate icons for the corresponding button, then set the General tab to the Properties page of the TBToolbar control The imagelist value is in the button value in the Buttons tab, allowing the above command button to correspond to the appropriate icon; (5) Select the Commondialog from the toolbox Add to the browser form, Named Commondialog1, prepare for the event code corresponding to the Open button; (6) Add a Label control Label1 to the form FORM1, set its CAPTION value to "Address (URL):", then in this control The location adds a COMBOBOX control Combo1 to generate a drop-down list box for a web address; (7) Add a WebBrowser Control WebBrowser1 to Form1, adjust it to the appropriate location; (8) Add a Timer Control Timer1, will Its Enabled and Interval Values are set to false and 5; (9) set the mdichild property value to false; (10) Set to the Form1 form in the properties window of the project. (11) Write the corresponding event program code for objects such as the corresponding form and each control, specifically refer to the front The program code, just replace the name of the object such as the corresponding form or control, the other basically, will not be described here. It is easy to design a simple web browser with a Visual Basic 5.0 ready-made browser (Browser) or using a WebBrowser control.
Compared with both methods, the former integrates some basic controls due to the browser form itself, and the corresponding code has been written, but it is just to write code for the added control or menu, so it looks It is more simple; and the latter is selected, added, designed, written code, etc. because of the objects such as each form or control, so it is relatively complicated. No matter how it can be expanded on this, it is designed to design a more advanced browser. PCC Private Sub Combo1_Click () WebBrowser1.Navigate Combo1.TextEnd SubPrivate Sub Combo1_KeyDown (KeyCode As Integer, Shift As Integer) Dim I As Long Dim existed As Boolean If KeyCode = 13 Then If Left (Combo1.Text, 7) <> "http : // "Then Combo1.text =" http: // " Combo1.text end if Webbrowser1.naVigate Combo1.text for i = 0 to Combo1.ListCount - 1 if Combo1.List (i) = Combo1.text the EXIXISTED = True EXIT for else existed = false end if next if not existed the combo1.additem (combo1.text) end if End iness sub
Private sub fascist1_click () WebBrowser1.gobackend Sub
Private sub fascist2_click () WebBrowser1.goforwardend Sub
Private Sub Form_Load () me.caption = "MY Explorer by xyuan" label1.caption = "web address:" Combo1.text = "http://iamxuyuan.go.nease.net" Progressbar1.zorder
End Sub
Private Sub Toolbar1_ButtonClick (ByVal Button As ComctlLib.Button) Select Case Button.Key Case "Exit" Unload Me Case "Back" WebBrowser1.GoBack Case "Forward" WebBrowser1.GoForward Case "Refresh" WebBrowser1.Refresh End Select
End Sub
Private sub webbrowser1_documentcomplete (Byval PDISP As Object, URL As Variant) Progressbar1.Value = 0nd Sub
Private sub webbrowser1_downloadbegin () statusbar1.simpletext = "Now from" & Combo1.Text & "Download" End Sub
Private Sub WebBrowser1_DownloadComplete () StatusBar1.SimpleText = "downloaded" ProgressBar1.Value = 0Me.Caption = WebBrowser1.LocationNameEnd SubPrivate Sub WebBrowser1_ProgressChange (ByVal Progress As Long, ByVal ProgressMax As Long)
If ProgressMax = 0 THEN EXIT SUB ProgressBar1.max = ProgressMax if Progress <> -1 and progress <= progressMax the progressbar1.value = progress endiff
End Sub
Private sub webbrowser1_titlechange (byval text as string) combo1.text = webbrowser1.locationurlend subbrowser1.locationurlend