O'Reilly logo

.NET Windows Forms in a Nutshell by Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Inheritance and Reuse

Inheritance is at the heart of the Windows Forms architecture—all visual classes inherit from the Control class. Not only does this ensure that there is a single programming interface for common user interface functionality, it also guarantees consistent behavior because all controls inherit the same implementation. Control authors need only write code for the features unique to their components, and developers that use these controls will not be troubled by subtle differences in behavior. This is a welcome improvement over ActiveX controls, the previous visual component technology in Windows, where each control had to provide a complete implementation of the standard functionality, with not entirely consistent results.

Inheritance can offer further benefits when we write our own UI components. Not only can we take advantage of the Control class’s features, we can also derive from other controls such as Button or TextBox. We can extend the behavior of almost any control, not just those built into the framework—third-party controls can also be used as base classes. The Forms Designer provides support for two special cases of inheritance: forms that inherit from other forms, and controls that derive from other composite controls. It allows us to edit such inherited components visually.

As mentioned in the previous chapter, inheritance must be used with care—deriving from a class makes a strong statement about your own class: you are declaring that your ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required