User control with base class cannot be viewed in designer

  • Thread starter Thread starter ....DotNet4Ever....
  • Start date Start date
D

....DotNet4Ever....

I am trying to develop several windows forms user controls for my
application, therefore all of these inherit from
System.Windows.Forms.UserControl as I drop them from the toolbox into the
design surface. I created the user control on the design surface and added
the other winform controls that are grouped into that user control. At this
point it shows fine in the designer. At this point I have

// SomeCompositeControl.cs
public partial class SomeCompositeControl : System.Windows.Forms.UserControl
{
}

// SomeCompositeControl.Designer.cs
public partial class SomeCompositeControl
{
private System.ComponentMode.IContainer components = null;
:
}


Well, In all my winforms and user controls I follow the same pattern. For
that reason I wanted to create an abstract base class for my user control (I
named it MementoUserControlBase):

public abstract class MementoUserControlBase :
System.Windows.Forms.UserControl
{
:
}

and then my user control would be:

// SomeCompositeControl.cs
public partial class SomeCompositeControl : MementoUserControlBase
{
}

// SomeCompositeControl.Designer.cs
public partial class SomeCompositeControl
{
private System.ComponentMode.IContainer components = null;
:
}

The problem is the moment I use the custom base class approach then when I
open my control designer surface rather than being greeted by my carefully
arranged custom user control I get:

"The designer could not be shown for this file because none of the classes
within it can be designed. The
designer inpsected the following classes in the file:
SomeCompositeControl -- the base class 'MementoUserControlBase' could not
be loaded. Ensure the asembly has been referenced and that all projects have
been built"

Both the user control (SomeCompositeControl) and the base class
(MementoUserControlBase) build properly and are in the same project. The
entire project builds without errors.

So, what is wrong here? what sort of weird designer intricacy am I missing?

Emilio
 
.....DotNet4Ever.... said:
The problem is the moment I use the custom base class approach then
when I open my control designer surface rather than being greeted by
my carefully arranged custom user control I get:

"The designer could not be shown for this file because none of the
classes within it can be designed. The
designer inpsected the following classes in the file:
SomeCompositeControl -- the base class 'MementoUserControlBase' could not
be loaded. Ensure the asembly has been referenced and that
all projects have been built"

Both the user control (SomeCompositeControl) and the base class
(MementoUserControlBase) build properly and are in the same project.
The entire project builds without errors.

So, what is wrong here? what sort of weird designer intricacy am I
missing?

Nothing is wrong. The designer displays an instance of the base class of the
class to be designed. As the base class is abstract, it is not possible.

You can only make the base class not abstract.


Armin
 
This is a limitation of the designer. It needs to instantiate the
base class of the class you are designing. Since the base class is
abstract, it can't.
 
A further problem was that the base class is generic and the designer just
craps out if the base class is generic. I did find a solution for that
though, and that is to create a specific class that just inherits from the
base generic class and then use this specific class (i.e. no generic
parameters) as the base of the control.
 
Back
Top