Flylib.com

Books Software

 
 
 

The Login Controls

 

Conclusion

The examples presented in this chapter, using the new Web site administration tool and login controls, clearly demonstrate that the ASP.NET 2.0 team reached its goal of a 70 percent reduction in code in some cases. I have not done any detailed analysis, but the number of lines of code directly related to user security in the BikeBlogSecured application is minimal, certainly 70 percent less than I would have expected were this an ASP.NET 1.x application.

In the next chapter, I will offer a brief overview of integrating a Web site into a Windows Forms application. Microsoft .NET Framework 2.0 also includes HtmlDocument and WebBrowser classes for Windows Forms applications. By using these classes, you can quickly create a Web browser of your own. In addition, I will take a quick look at other ways to integrate Windows Forms and Web Forms applications.

 
 

Chapter 8: Integrating with Windows Forms Applications

Overview

After writing seven chapters about the wonders of Web Forms applications, I must acknowledge that Web Forms applications are not the complete solution to every problem. As the Microsoft ASP.NET team worked on improvements and enhancements, the team supporting Microsoft Windows Forms applications was not standing still.

Improvements to Windows Forms applications have not taken place in isolation from the Internet and Web Forms applications. For example, ClickOnce deployment of Windows Forms applications is a new feature of Windows Forms applications in .NET 2.0 that leverages the Internet. Traditionally, Windows Forms applications required a multi-step installation process on each workstation running the application. ClickOnce deployment uses the Internet or an intranet for both initial deployment and updates of a Windows Forms application.

A less-heralded improvement, but one that is significant for Web Forms developers, is the inclusion of the WebBrowser control. The WebBrowser control is a managed wrapper around the Microsoft ActiveX control that Microsoft Internet Explorer uses to display Web pages. Strictly speaking, developers always could use the ActiveX Web browser control in their applications; however, the WebBrowser control makes it a great deal easier. The WebBrowser control is the focus of this chapter. Details will follow, but first, let's take a brief look at what the control can do.

 
 

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.

image from book
Figure 8-1: The New Project dialog box in Visual Studio, set to add a new Windows Forms application

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.

image from book
Figure 8-2: New Windows Forms application in Design view

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.

image from book
Figure 8-3: Windows Forms application displaying the Microsoft Press home page in a WebBrowser control

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.