Chapter 8. Windows Forms

If the goal of Microsoft .NET is to embrace the Web, what will happen to conventional Windows applications? As it turns out, the .NET Framework not only benefits the development of web applications, but also improves the way standard Windows applications are built. In this chapter, we provide you with an understanding of what Windows Forms are, how to use Windows Forms .NET classes to create Windows Forms-based applications, and how you can still “embrace the Web” while creating Windows applications.

Introducing Windows Forms

If you have developed Windows applications since the early 1990s, chances are that you have seen and used raw Windows APIs such as RegisterClass, CreateWindow, ShowWindow, GetMessage, TranslateMessage, and DispatchMessage. You certainly had a WinMain entry point in your application. Inside this function, you registered your application with Windows, created and showed the window, and handled messages from the system. Every Windows application has to have a message loop that collects Windows messages and dispatches them to the message-handler function that you’ve registered through RegisterClass function. As the developers, much of your job is handling Windows messages, such as WM_CREATE, WM_SIZE, or WM_CLOSE, that you create and pump into the system with PostMessage or SendMessage.

Classic Windows development is tedious and error-prone. The result is that application frameworks were built as an abstraction on top of all these Windows ...

Get .Net Framework Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.