The Microsoft .NET Framework is chiefly a platform for writing Web applications and Web services, but it supports other programming models as well. Chapter 3 spotlighted console applications and even threw in a Web application for good measure. This chapter is about Windows Forms鈥攖he programming model used to write GUI applications for the .NET Framework.
On the outside, Windows Forms applications look like ordinary Windows applications. They have windows, and they frequently incorporate common GUI application elements such as menus, controls, and dialog boxes. On the inside, they鈥檙e managed applications in every sense of the word. They contain common intermediate language (CIL) and metadata, they use the .NET Framework class library (FCL), and they run in the highly managed environment of the common language runtime (CLR).
The chief benefit to writing Windows applications the Windows Forms way is that the framework homogenizes the GUI programming model and eliminates many of the bugs, quirks, and inconsistencies that plague the Windows API. For example, every experienced Windows programmer knows that certain window styles can be applied to a window only when the window is created. Windows Forms largely eliminates such inconsistencies. If you apply a style that鈥檚 only meaningful at creation time to an existing window, the framework quietly destroys the window and re-creates it with the specified style. In addition, the FCL is much richer than the Windows API, and when you write Windows Forms applications, you have the full power of the FCL at your disposal. More often than not, Windows Forms applications require less code than conventional Windows applications. For example, an application written to the native Windows API requires hundreds of lines of code (or a third-party graphics library) to extract an image from a JPEG file. A Windows Forms application needs just one.