我创建了一些控件并定义了一些可以在设计时定义的属性,但只显示一个。 另一个问题是,在显示的那个中,显示了表单的文本框,但我无法选择任何内容。
[Description("Blah Blah Blah"),
Category("Data"),
DefaultValueAttribute(typeof(TextBox), null),
Browsable(true)]
//Only show this one
public TextBox textBox
{
set { txt = value;}
}
[Description("Blah blah blah again"),
Category("Data"),
DefaultValueAttribute(typeof(string), null),
Browsable(true)]
public string Mensaje
{
set { sMensaje = value; }
}
所以,我的代码有什么问题
最佳答案
您的属性缺少 setter/getter 。
// Snip attributes
public TextBox textBox
{
get { return txt; }
set { txt = value;}
}
// Snip attributes
public string Mensaje
{
get { return sMensaje; }
set { sMensaje = value; }
}
关于c# - 通过自定义控件 (.NET) 在设计时提供属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2297492/