表单设计器打破通用抽象UserControl

Pet*_*ron 7 c# inheritance templates partial-classes windows-forms-designer

我有一个通用的抽象UserControl类,SensorControl我希望我的所有传感器控制面板都可以继承.

问题

尝试EthernetSensorControl在Visual Studio中设计(我继承的UserControl表单之一)时,表单设计器中显示以下错误:

无法为此文件显示设计器,因为其中的所有类都无法设计.设计人员检查了文件中的以下类:DeviceSensorControl ---无法加载基类"Engine.Sensors.SensorControl".确保已引用程序集并且已构建所有项目.

SensorControl 类:

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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

示例继承的类,EthernetSensorControl:

namespace Engine.Sensors
{
    public partial class EthernetSensorControl
        : SensorControl<EthernetSensor>
    {
        public EthernetSensorControl(EthernetSensor sensor)
            : base(sensor)
        {
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和调用堆栈:

在Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)的System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)的System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)中在System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost主机)

一切都编译好,我可以看到显示的面板,但我无法设计它.我认为问题可能与partial课程有关.有任何想法吗?

SLa*_*aks 9

您无法设计继承abstract类的控件或表单.

(设计者需要实例化基类作为设计图面)

基类还需要一个无参数构造函数供设计者调用.
这个构造函数可以是私有的.