Now, let's look at a more complex example using one of the new controls that was introduced with Visual Basic 2005: the WebBrowser control.
This control allows you to embed a Web browser right in your Windows application. (I know, you could do this before, but this control is still new.)
The steps to create your own unique version of this control are the same as with the Button control (including the bug) so I'll skip them and get right to the code. The code is very similar to the button code, but does more.
Public Class AVB_Browser
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
Try
Me.Navigate(New Uri("http://visualbasic.about.com"))
Catch ex As System.UriFormatException
MsgBox("catch in navigate")
Return
End Try
End Sub
Private Sub AVB_Browser_Navigating( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) _
Handles Me.Navigating
Debug.WriteLine(e.Url.ToString)
If Split(e.Url.ToString, ".")(1) <> "about" Then e.Cancel = True
End Sub
End Class
Since everyone should start every web session with the About Visual Basic web page, I initialize the WebBrowser with a navigate call. But, if you're like me, you don't like seeing all of the popup ads on the page! Just like "free" TV, the ads pay for the page. But just like TV, we can use technology to screen them out! In this case, I use the fact that all pages associated with my 'real' site have 'about' in the domain. I also use the Split function that was suggested by my good friend, Dr. Ingerman to select the domain name.
The result is a Windows application where my page pops up - no fuss, no bother!
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

