Datasheet
4. Now that you’re done with design, all you need to do is add the code to make the button react
when clicked. Just as you did in the previous Try It Out, double-click on the button to generate
the code necessary to hook into the click of the button.
5. The only thing you need to do in the code is tell the WebBrowser control to go to the URL speci-
fied in the
TextBox control. The properties you see in the Properties window are also accessible
in code. The way you access these properties is by specifying the name of the control followed
by a period (.) and then the name of the property. Methods are functions connected to an object,
and they execute a certain task. In this case, you need the
Text property of the TextBox control
to get the URL text, and the
Navigate method of the WebBrowser control to tell it to go to the
URL. This is all achieved with the following line of code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
6. Run the program by pressing F5 or selecting the Start command on the Debug menu. When the
form is displayed, type a URL in the text area, such as
http://www.wrox.com, and then click
the Go button. After a moment, the web browser area of the form will be populated with the
web page associated with the URL, as shown in Figure 1-8.
Figure 1-8
As you can see, creating what appears to be a fairly complex program is made simple in Visual Basic
2005 Express. The controls used to create this program, along with the techniques known as method and
property access in code, are discussed in the next few chapters.
14
Chapter 1
05_595733 ch01.qxd 12/1/05 1:34 PM Page 14