Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Listing 21.1 browser.frm version 1

VERSION 6.00
Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "SHDOCVW.DLL"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7560
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   7560
   StartUpPosition =   3  'Windows Default
   Begin ComctlLib.Toolbar Toolbar1
      Align           =   1  'Align Top
      Height          =   630
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   7560
      _ExtentX        =   13335
      _ExtentY        =   1111
      ButtonWidth     =   1164
      ButtonHeight    =   953
      Appearance      =   1
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628}
         NumButtons      =   6
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628}
            Caption         =   "Back"
            Key             =   "Back"
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628}
            Caption         =   "Next"
            Key             =   "Next"
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628}
            Caption         =   "Home"
            Key             =   "Home"
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628}
            Caption         =   "Stop"
            Key             =   "Stop"
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628}
            Caption         =   "Refresh"
            Key             =   "Refresh"
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628}
            Style           =   4
            Object.Width           =   100
         EndProperty
      EndProperty
      Begin VB.ComboBox Combo1
         Height          =   315
         Left            =   3480
         TabIndex        =   2
         Top             =   120
         Width           =   3975
      End
   End
   Begin SHDocVwCtl.WebBrowser WebBrowser1
      Height          =   2295
      Left            =   120
      TabIndex        =   0
      Top             =   840
      Width           =   7335
      ExtentX         =   12938
      ExtentY         =   4048
      ViewMode        =   1
      Offline         =   0
      Silent          =   0
      RegisterAsBrowser=   0
      RegisterAsDropTarget=   1
      AutoArrange     =   -1  'True
      NoClientEdge    =   0   'False
      AlignLeft       =   0   'False
      ViewID          =   "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
      Location        =   ""
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
    WebBrowser1.Navigate "www.microsoft.com"
    Combo1.Text = "www.microsoft.com"
    Combo1.AddItem Combo1.Text
End Sub

Private Sub WebBrowser1_DownloadComplete()
    Me.Caption = WebBrowser1.LocationName
    Combo1.AddItem WebBrowser1.LocationURL, 0
End Sub

Private Sub Combo1_Click()
    WebBrowser1.Navigate Combo1.Text
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        Combo1_Click
    End If
End Sub

Adding Back And Forward Buttons To A Web Browser

Now that we’ve set up a Web browser in which the user can navigate by typing URLs into the combo box (see the previous topic), we’ll enable the Back and Forward buttons in the browser.

That’s easier than you might expect—you just use the browser’s GoBack or GoForward methods. We do that like this, where we determine which button in the toolbar has been clicked by checking the keys we’ve added to those buttons:

Private Sub Toolbar1_ButtonClick(ByVal Button As Button)
    Select Case Button.Key
        Case "Back"
            WebBrowser1.GoBack
        Case "Forward"
            WebBrowser1.GoForward
    End Select
End Sub

And that’s all there is to it—now the user can navigate forwards and backwards in the browser’s history. We’ve added Back and Forward buttons now, but the user also expects Refresh, Home, and Stop buttons in Web browsers, and we’ll add those buttons next.

Adding Refresh, Home, And Stop Buttons To A Web Browser

In the previous few topics, we’ve set up a Web browser complete with combo box to let the user enter and select URLs, as well as a Back and Forward button to let the user navigate through the browser’s history. However, we still have a few more buttons to implement: the Refresh, Home, and Stop buttons.

We can implement those buttons with the Web browser control’s Refresh, GoHome, and Stop methods. We’ve given the Refresh, Home, and Stop buttons the keys “Refresh”, “Home”, and “Stop”, so we just call the appropriate Web browser method when the matching button is clicked (note that if the user clicks the Stop button, we also update the current URL as displayed in the browser’s title bar using the Web browser’s LocationName property):

Private Sub Toolbar1_ButtonClick(ByVal Button As Button)
    Select Case Button.Key
        Case "Back"
            WebBrowser1.GoBack
        Case "Forward"
            WebBrowser1.GoForward
        Case "Refresh"
            WebBrowser1.Refresh
        Case "Home"
            WebBrowser1.GoHome
        Case "Stop"
            WebBrowser1.Stop
            Me.Caption = WebBrowser1.LocationName
    End Select
End Sub

Now the user can use the new buttons, Refresh, Home, and Stop. The code for the finished Web browser is located in the browser folder on this book’s accompanying CD-ROM.


TIP:  You used to be able to specify the browser’s search page in the Internet Explorer, but as of Internet Explorer version 4, you are taken to a page of Microsoft’s choosing. If you still want to implement a Search button, however, just use the WebBrowser control’s GoSearch method.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.