我有一个通用摘要UserControl
class, SensorControl
,我希望所有传感器控制面板都继承它。
问题
当尝试设计时EthernetSensorControl
(我从 Visual Studio 继承的 UserControl 表单之一,表单设计器中显示以下错误:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: DeviceSensorControl --- The base class 'Engine.Sensors.SensorControl' could not be loaded. Ensure the assembly has been referenced and that all projects have been 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;
}
}
}
示例继承类,EthernetSensorControl
:
namespace Engine.Sensors
{
public partial class EthernetSensorControl
: SensorControl<EthernetSensor>
{
public EthernetSensorControl(EthernetSensor sensor)
: base(sensor)
{
}
}
}
和调用堆栈:
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
一切都编译完毕,我可以看到显示的面板,但我无法设计它。我认为问题可能与partial
类。有任何想法吗?
您不能设计继承某个控件或窗体abstract
class.
(设计者需要实例化基类作为设计图面)
基类还需要有一个无参数构造函数供设计者调用。
这个构造函数可以是私有的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)