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!
A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus. Set the AcceptButton or CancelButton property of a Form to allow users to click a button by pressing the ENTER or ESC keys even if the button does not have focus.
Set the WindowState property of your form to Maximized . That will cause your form to be maximumized when it's opened. In addition, the FormBorderStyle can be set to FormBorderStyle. None to remove the border as well, for a more true maximized feeling, no borders added.
Extending a button control is no different then extending any class in C#. Simply do the following:
class ToggleButton : Button {
// Add your extra code
}
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.
I know this is old and has been answered - however, Why make life difficult?
Each control has a Tag property which you can easily set to IsSwitchedOffable - or better English CanBeDisabled
Far easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With