The Form Class
All
windows in a Windows Forms application
are represented by objects of some type deriving from the
Form
class. Of course, Form
derives from Control
, as do all classes that
represent visual elements, so we have already seen much of what it
can do in the previous chapter. But we will now look at the features
that the Form
class adds.
You will rarely use the Form
class
directly—any forms you define in your application will be
represented by a class that inherits from Form
.
Adding a new form in Visual Studio .NET simply adds an appropriate
class definition to your project. We will examine how it structures
these classes when generating new forms, and we will look at how it
cleans up any resource used by the form when it is destroyed. Then,
we will consider the different types of forms. Finally, we will look
at extender properties. These provide a powerful way of extending the
behavior of all controls on a form to augment the basic
Control
functionality.
The Forms Designer
Most forms are designed using the Forms Designer in Visual Studio .NET. This is not an essential requirement—the designer just generates code that you could write manually instead. It is simply much easier to arrange the contents of a form visually than it is to write code to do this.
When you add a new form to a project, a new class definition is
created. The Designer always uses the same structure for the source
code of these classes. They begin with private
fields in C# and Friend
fields in VB to ...
Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.