7

我有一个通用抽象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;
        }
    }
}

示例继承类,EthernetSensorControl

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

和调用堆栈:

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

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

4

1 回答 1

9

您不能设计继承abstract类的控件或窗体。

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

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

于 2010-10-14T12:49:11.370 回答