c# - Windows 窗体设计器和通用窗体

标签 c# .net winforms generics

如果您继承自自己编写的通用表单,为什么设计器不起作用?

假设我有以下通用形式

public class GenericForm<T> : System.Windows.Forms.Form
{
    public T Test
    {
        get;
        set;
    }
}

当我去找设计师时,我遇到了错误。

我提出的唯一解决方法是使用编译器指令。

#if DESIGN    
    public partial class Form1 : System.Windows.Forms.Form
#else
    public partial class Form1 : GenericForm<string>
#endif

    {
        public Form1()
        {
            InitializeComponent();
        }
    }

最佳答案

我相信这是因为设计器尝试实例化表单(或 UserControl)以将其托管在设计器中。如果您有通用(或抽象)形式,设计者无法实例化它。

关于c# - Windows 窗体设计器和通用窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/314033/

相关文章:

c# - 停靠栏更改时 UserControl 未在 FlowLayoutPanel 中呈现

c# - 如何在 C# 中实现 SOAP 客户端(专门针对 Windows Mobile)?

c# - 通过Selenium点击Captcha总是引发图片验证

c# - 从 AntiForgeryToken() 获取原始值(不是 html)

c# - 在设计器中创建一个具有固定高度的自定义控件

c# - Graphics.IsVisible(Rectangle rect) 的文档有误吗?

c# - 如何输出exe使用的所有.NET框架DLL

c# - 使用 itextSharp 在 Chunk 中制表符

C# Azure Function App 部署时的行为有所不同

c# - 为什么 .NET Framework 会锁定 dll?