tags:

views:

45

answers:

2

How can I extend a Button?

I want a Button that has an additional property IsSwitchOffable.

Do I have to write an extra custom control?

EDIT: I want that the button is usable as a standard WindowsFormsButton.

This includes that I can add the button at design time!

+2  A: 

You need to create a class that inherits the System.Windows.Forms.Button class and adds your property and associated behavior.

After compiling your project, your new class will appear in the toolbox.

SLaks
cool, how can I show the new property in the property window?
Rookian
@Rookian: You can simply make a normal public property in your class, and it will appear in the Properties window. You may want to add `Description`, `Category`, or `DefaultValue` attributes.
SLaks
... really really simple, I did not expect that this is so easy.
Rookian
+3  A: 

Extending a button control is no different then extending any class in C#. Simply do the following:

class ToggleButton : Button {
// Add your extra code
}
icemanind