O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

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

Subclassing an Existing Control

Subclassing an existing control is the best approach if your needs are only slightly different from one of the standard .NET Framework controls. By inheriting from an existing control class, you are riding on top of its behavior and appearance; it’s up to you to then add the specialized code to your new control class.

For example, suppose that you want a text box that turns red anytime a numeric (that is, nonalphabetic) character is entered. This is easy to do with just a few lines of code sitting in the TextBox control’s TextChanged event, but consolidating this behavior into its own class provides a reuse factor.

You start by adding a new user control to the project. User controls actually inherit from the UserControl ...

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