Windows Forms Basics

At its core, Windows Forms is a collection of classes all created in the .NET Framework. These classes provide a completely object-oriented encapsulation of creating and manipulating user interface elements such as forms, dialog boxes, user input, enhanced graphical output, and much more.

Although you can create virtually any type of application using the .NET Framework SDK and Notepad, Visual Studio includes a plethora of tools and designers that make creating Windows Forms applications a smooth and efficient process that has become even faster and more powerful with the current version of Visual Studio.

Figure 34.1 illustrates how Windows Forms fits in with the rest of the .NET Framework, including ASP.NET applications, Windows Service applications, and console applications.

Figure 34.1. Windows Forms within the .NET Framework.

Because of the object-oriented nature of the .NET Framework and of Windows Forms, you can accomplish a lot of things with Windows Forms that are virtually impossible without it. For example, you can use inheritance to create forms that inherit from other forms and you can also use inheritance to create your own custom controls that derive from existing controls. For example, with only a few lines of code you could create a text box with your own custom behavior added to it while reusing all of the existing behavior inherent in a text box control.

Windows Forms Versus Web Forms

One of the most common tasks when designing a new application is deciding whether to use Windows Forms or Web Forms. The incredible power, flexibility, and scalability of applications developed using the .NET Framework blurs the line between traditional Windows applications and web applications.

Windows Update Is Your Friend

Ever since Windows Update started pushing the .NET Framework 1.0 to Windows users through its BITS background transfer system, developers of .NET applications have been extremely happy. The reason is that before that time, developers could not count on users already having the .NET Framework on their machines, so deployment of Windows Forms applications was problematic. With .NET 2.0 available through Windows Update, developers can actually make the business assumption that the majority of Windows XP users already have the .NET Framework installed on their PCs. This is a tremendous advantage in the Windows versus web argument in terms of ease of deployment.

There are many arguments for and against Windows Forms applications. Most of the positives for Windows Forms include the fact that a Windows Forms application can have a far more interactive and graphically rich interface, whereas Web Forms applications tend to take less time to build. Table 34.1 takes a look at the various concerns for building applications and indicates whether Web Forms or Windows Forms (or both) support such features.

Table 34.1. Decision Support Table: Windows Forms Versus Web Forms



Web Forms



Deployment of Windows Forms applications is made easier using ClickOnce, whereas web applications are available via a web browser that virtually all Windows users possess. Web applications are still often considered "zero deployment" applications, however.

Time to Market


In most cases, web applications of similar complexity take less time to develop than their Windows Forms counterparts.




The time and effort required to produce the same highly interactive environment that is the Windows Forms hallmark in an ASP.NET application negates ASP.NET's time-to-market advantage.


Rich User Interface


Both Windows and Web Forms can create extremely rich and visually pleasing user interfaces in their own ways with their own strengths. However, combining the interactivity and reactivity of WinForms here with GDI+ (2D graphics) capability gives Windows Forms the edge.



Because both ASP.NET and Windows Forms are based on the .NET Framework, they can both scale equally well within their own environments using core .NET technologies.



Web applications can be expanded using web farms, out-of-process state management, and much more. Both application types can make use of COM+ services, remoting, and web services to build distributed solutions.



Windows Forms applications can be converted to run on the Compact Framework for PocketPCs, whereas ASP.NET applications can dynamically render "lite" markup depending on the feature set of the mobile browser.

The bottom line is that although the two platforms are radically different in their purpose, they have very few technical differences that would sway a developer in one direction over the other. In most cases, the decision of Windows versus web comes down to the type of application being created and the environment in which it must be deployed. Time to market and interactivity are the only two major categories in which ASP.NET and Windows Forms evince a large difference in ability. The rest of this chapter should get you started building Windows Forms applications.

Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298 © 2008-2017.
If you may any questions please contact us: