I’m writing a bunch of user controls that each acts as a ”page” in a wizard-style
application. The setup, teardown and state management in each user control class are
similar. I’d like to have an abstract base class (let’s call it AbstractPageBase),
that inherits from System.Windows.Forms.UserControl and rovides a implementation
of the setup and teardown stuff, with calls to abstract methods (eg GetPageStateFromDatabase)
that the derived classes override to plug in their custom initialization code.
And it works fine. The stuff compiles and works as expected. The problem is when I
want to look at a derived component (let’s call it MyDerivedPage) using the VS.Net
form designer. I get an error message stating that the designer must create an instance
of PageBase, but fails since it’s abstract.
If I make PageBase non-abstract (changing all the abstract methods to virtual), the
designer can show derived controls. But that’s annoying, since I’m not guaranteed
to override all the methods I need to override. Furthermore, I cannot understand why
the designer needs to create an instance of the base class of the control I want to
edit. Why doesn’t it create an instance of the actual control instead?
Update: Jacob Grass explains why
this is, and how to work around it.