Programming Microsoft Web Forms (Pro Developer)
WebBrowser Control Example
To test out the new WebBrowser control, we first need to create a new Windows Forms application. In Microsoft Visual Studio 2005, select New on the File menu, and then select Project. The New Project dialog box appears, as shown in Figure 8-1.
In the Project Types list on the left, expand Visual C#, and then select Windows. Select Windows Application from the list of installed templates on the right. Name the project WindowsWebAccess. Click OK, and you will see a screen like the one shown in Figure 8-2.
From the Common Controls group of the Toolbox, drag and drop a WebBrowser control onto the form. The control is automatically sized to take up the entire form. In the Properties window, you can set properties just as you can for Web Forms controls. One of the properties of the WebBrowser control is the Url property. Set this property to www.microsoft.com/learning/books/. On the Debug menu, select Start Debugging (or press F5) to run the application. Maximize the form, and you will see the Microsoft Press home page, similar to the page shown in Figure 8-3.
With no code, and a single property setting, we have a very simple, serviceable Web browser. If you right-click the WebBrowser control, the menu that appears is the same menu that appears when you right-click a Web page in Internet Explorer, allowing you to go back and forward, view the source of the page, and so on.