I created a C# class that extends Button, but associates a generic type like this:
public class DropButton<T> : Button where T : INamed
{
//contains lots of properties and methods that
//reference and operate on the objects of type T
}
...where INamed interface specifies what properties any class should have to be used with my DropButton:
public interface INamed
{
string Name { get; set; }
bool Selected { get; set; }
}
I can add an instance of the control on a WinForms form programmatically:
private DropButton<MySet> MyDropButton = new DropButton<MySet>();
//Then set properties of the control in the form constructor and add it.
It works splendidly and it keeps my form code a lot cleaner.
However, the new control does not show up in the Toolbox for the project. Nor does the designer recognize the code if I manually modify the .Designer.cs file with an instance of it.
So two questions:
- Is there a way to trick the WinForms form designer to allow it in design mode?
- Is there a better way to go about this pattern?