在一般的抽象用户控件窗体设计器断裂 [英] Form designer breaks on generic abstract UserControl
问题描述
我有一个通用的抽象用户控件
类, SensorControl
,我想我所有的传感器控制面板继承
I have a generic abstract UserControl
class, SensorControl
, which I want all my sensor control panels to inherit from.
在试图设计 EthernetSensorControl
(我继承用户控件的形式之一,从Visual Studio中,显示在窗体设计器中出现以下错误:
When attempting to design the EthernetSensorControl
(one of my inherited UserControl forms, from within Visual Studio, the following error is displayed in the form designer:
<块引用>设计者可能无法显示。这个文件,因为没有在它的类可以设计设计器检查下列类文件中:DeviceSensorControl ---基类的Engine.Sensors.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
:
Example inherited class, EthernetSensorControl
:
namespace Engine.Sensors
{
public partial class EthernetSensorControl
: SensorControl<EthernetSensor>
{
public EthernetSensorControl(EthernetSensor sensor)
: base(sensor)
{
}
}
}
和调用堆栈:
<块引用>在System.ComponentModel .Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager经理)
在System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager经理)
在Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad (IDesignerSerializationManager serializationManager)在System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost主机)
块引用>
编译一切,我可以看到面板中显示,但我不能设计它。我认为这个问题可能会涉及到部分
类。任何想法?
Everything compiles and I can see the panel displayed, but I can't design it. I think the problem may be related to the partial
classes. Any ideas?
推荐答案
您不能设计继承了摘要<控件或窗体/ code>类。
You cannot design a control or form that inherits an abstract
class.
(设计师需要实例化基类来作为设计界面)
(The designer needs to instantiate the base class to serve as the design surface)
基类也需要有一个参数的构造函数为设计师打电话。结果
此构造可以是私有的。
The base class also needs to have a parameterless constructor for the designer to call.
This constructor can be private.
这篇关于在一般的抽象用户控件窗体设计器断裂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!