Last Updated:

Windows Forms Hierarchy (Windows Forms)

Unfortunately, the Forms Designer is not supported in C++. However, you can use the Forms Designer in C# and then port the GUI code you receive with C# to a C++ program. Porting a graphical user interface to a C++ program requires additional effort and, in most cases, such a porting is not particularly useful. As a rule, C++ is not used to develop user interfaces, instead a language mixing approach is used, in which C# is used to create the user interface, and other aspects of project development use C++ for various reasons.

Since you will most likely have to often create a graphical user interface for many applications, in this pavement we have two goals. First, we want to teach you how to share C# and C++ code. Even if you're mostly programming in C++, it's worth familiarizing yourself with C# and the Forms Designer—you'll be able to use those powerful tools that aren't supported in C++. Second, we will give an example of one of the few cases where porting GUI code from C# to a C++ program is appropriate. This chapter introduces several pairs of graphical user interface code examples before and after migration.

The key means of user interaction with the computer is the Graphical User Interface (GUI). In this chapter, you will learn how to create a graphical user interface by using the Windows Forms classes that reside in the NET Framework. In practice, programming Windows applications involves the extensive use of various tools and wizards that greatly simplify this process. However, all of these automations obscure what is at the heart of creating a graphical user interface. So first, we'll look at the basics of creating graphical user interfaces. In other words, we'll learn how to create simple Windows applications from the start, using only the NET Framework SDK.

This means that first we will create simple Windows applications without the use of any special service programs. You will learn the basics of drawing with Windows Forms with fonts and brushes, as well as the event handlers that you need. We will explain how to handle events in Windows Forms and implement mouse event handlers. Using Windows Forms, we also implement menus and corresponding event handlers.

We'll also take a look at the controls, and then explore The Visual Studio .NET environment, which makes it easy to create a simple graphical user interface in C#. Using the Forms Designer, we'll add controls to the form, create menus, add event handlers, and add other useful functionality. If desired, the resulting C# project can then be transferred to C++. Finally, we will look at dialog boxes and a control such as a list.


Windows Forms are the part of the .NET Framework that supports the creation of applications with a standard graphical user interface (GUI) on the Windows platform. Among the Windows Forms classes, there is an extensive set of classes for creating complex graphical user interfaces. You can use these classes in applications written in any .NET language.

Typically, your application will contain a main window that is implemented using some myForm class that derives from the Form class. Figure 6.1 shows where your MyForm class ranks in the Windows Forms class hierarchy.

 

Windows Forms Class Hierarchy Diagram

Simplified Windows Forms Class Hierarchy Diagram (Windows Forms)