Displaying Web Documents
Create a new form and name it frmWeb
.
Resize the form to 800,700
and drag a Web Browser from the Toolbox onto the new form. You'll find that it fills the form. Click on the smart tab and click on the "Undock in parent container" link, as shown in Figure 3-4.
Figure 3-4. Undock the web form
Shrink the web form down just enough to add a text box (which you'll name txtURL
) and four buttons (btnGo, btnHome, btnPrevious, and btnNext), as shown in Figure 3-5.
Figure 3-5. Designing the web browser
Setting Web Browser Event Handlers
It would be useful to disable the Previous button when it is not possible to go back any further, and to disable the Next button when there is no next page. The Web Browser
has two properties (CanGoBack
and CanGoForward
) that you can test. Rather than testing these every time the form is navigated, it's more efficient to respond to the events that fire when these properties changeâCanGoBackChanged
and CanGoForwardChanged
âas shown in Example 3-4.
Example 3-4. CanGoBackChanged and CanGoForward event handlers
Private Sub WebBrowser1_CanGoBackChanged
( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles WebBrowser1.CanGoBackChanged btnPrevious.Enabled = WebBrowser1.CanGoBack End Sub Private Sub WebBrowser1_CanGoForwardChanged ...
Get Programming Visual Basic 2005 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.