The designer of forms is divided into the general abstract UserControl

I have a generic UserControl abstract class, SensorControl , which I want all sensor control panels to inherit from.

Problem

When trying to create an EthernetSensorControl (one of my inherited UserControl forms from Visual Studio, the following error appears in the form designer:

A designer cannot be shown for this file, because none of the classes inside it can be designed. The designer checked the following classes in the file: DeviceSensorControl --- Failed to load the base class "Engine.Sensors.SensorControl". Make sure that the assembly contains links and that all projects are built.

SensorControl class:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace Engine.Sensors { public abstract class SensorControl<SensorType> : UserControl where SensorType : class { protected SensorType _sensor; public SensorControl(SensorType sensor) { _sensor = sensor; } } } 

An example of a legacy EthernetSensorControl class:

 namespace Engine.Sensors { public partial class EthernetSensorControl : SensorControl<EthernetSensor> { public EthernetSensorControl(EthernetSensor sensor) : base(sensor) { } } } 

And the call stack:

in System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument (manager IDesignerSerializationManager) in System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoadManer.DesignerMenery.DesignerMenery.DesignerService.DesignerServer in System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad (host IDesignerLoaderHost)

Everything compiles and I see that the panel is displayed, but I cannot create it. I think the problem might be related to partial classes. Any ideas?

+7
inheritance c # templates partial-classes windows-forms-designer
source share
1 answer

You cannot create a control or form that inherits the abstract class.

(The designer must create an instance of the base class that will serve as the design surface)

There should also be a constructor without parameters in the base class, which can call the constructor.
This constructor may be private.

+9
source share

All Articles