gpt4 book ai didi

c# - 设置自定义控件属性

转载 作者:行者123 更新时间:2023-11-30 15:11:09 25 4
gpt4 key购买 nike

我以为它会很简单,但我今天做不到。

我有一个用户控件,其中包含一个网格控件。

public Unit Width
{
get
{
return CustomerGrid.Width;
}
set
{
CustomerGrid.Width = value;

}
}

我公开了 width 属性,当我在设计器中设置它时,它在运行时起作用,但在设计时不起作用。

我从什么类继承或重写什么方法才能让我的控件在设计时发挥作用。

请注意,我试图从 WebControl 继承,但收到了消息

Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class 

最佳答案

我知道您是在谈论用户控件 (ascx),而不是自定义控件(无 ascx)。如果是这种情况,您应该从 UserControl 继承并且您将在设计时拥有可用的属性,而无需任何其他添加。

如果您正在谈论自定义控件,这里有一篇关于向自定义控件添加设计时支持的好文章

http://msdn.microsoft.com/en-us/library/aa478960.aspx

关于c# - 设置自定义控件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2678367/

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