O'Reilly logo

Visual C# 2005: A Developer's Notebook by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Put the Web in a Window

.NET 2.0 provides a WebBrowser control that you can drag and drop directly into a Windows application. This gives you a full-featured Internet Explorer 6 browser embedded in your application, with virtually no coding required.

How do I do that?

Note

You can drag a full featured Internet Explorer 6 browser directly in to your Windows application.

Create a new Windows application (WebBrowsing) and enlarge the form to hold a reasonably sized browser and a couple of other controls. Drag a WebBrowser control onto your form. You'll notice that it fills the form, but if you use its smart tag to click Undock in the parent container, you'll find you have a resizable WebBrowser control within the form.

Note

Notice that loading the page is accomplished asynchronously--for example, your application keeps running while the page is loading.

Click the URL property of the WebBrowser control and type the URL of your favorite web site (for example, http://www.LibertyAssociates.com). Run the application and voila! You're browsing my site.

Let's add a few useful controls: a text box (with auto-complete for URLs), a progress bar, and Back and Forward buttons.

The browser control fires a number of useful events as the page is loading. Some of the most useful are shown in Table 3-6.

Table 3-6. Browser events

Browser event

Description

Navigating

Raised when you set a new URL, or when the user clicks a link. (Use this to cancel navigation.)

Navigated

Raised just before the web browser begins ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required