views:

183

answers:

1

I've come across the feature in Visual studio to auto-generate a subclass of a custom control using Add New Inherited User Control.

But I haven't found a clear description on how to e.g create a subclass of Button for instance. Apart from the actual way to do it, I'm also interested if VS provides helpful code-generation for this?

+1  A: 

You just create your own class that inherits the Control, that you would like to subclass. For instance:

class BetterButton : Button { ...}

That is the easy part. Now you have the option to override various methods or properties, depending on what you want to achieve with your new Control. It could be anything, really. One thing I often see used is overriding OnPaint to get the control drawn in a custom way; and still getting the behaviour of the original control.

In terms of UserControls, I often see that a "parent" UserControl contains some UI logic and basic UI elements, while the subclassed controls are refinements of the parent for specific use.

driis