gpt4 book ai didi

c# - “Could not find type” 在设计器中加载窗体时出错

转载 作者:太空宇宙 更新时间:2023-11-03 16:56:07 25 4
gpt4 key购买 nike

这个问题与这个问题完全相同:“Could not find type” error loading a form in the Designer

在任何人结束我的问题之前,请阅读那个。你会意识到它没有得到真正的答案。我希望从这个问题中得到完整的答案(而不是解决方法)。

当我创建一个派生自 Control 并使用泛型的类时,该类无法在设计器中加载。

这是一个例子:

class OwnerDrawnListBox<T> : System.Windows.Forms.Control
{

private readonly List<T> _items;

// Other list box private stuff here

public OwnerDrawnListBox()
{
_items = new List<T>();
}

// More List box code
}

然后我在我的设计器中使用它:

private OwnerDrawnListBox<Bag> lstAvailable;

private void InitializeComponent()
{
// Used to be System.Windows.Forms.ListBox();
this.lstAvailable = new ARUP.ScanTrack.Mobile.OwnerDrawnListBox<Bag>();
// Other items
}

如果泛型类被子类化(非泛型),那么引用的问题说它工作正常(即如果我做了 Class BagOwnerDrawListBox: OwnerDrawnListBox<Bag> )。

我想知道有什么方法可以“修复”这个问题,以便设计师接受通用项目?

旁注:我使用的是 Compact Framework。

最佳答案

据我所知,Windows 窗体设计器不支持通用控件。维护设计器支持的唯一方法是使用非通用子类,就像你说的那样。无论如何,任何“修复”都只是一种解决方法。

关于c# - “Could not find type” 在设计器中加载窗体时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2001264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com