我有一个带有字符串属性的 Windows 窗体用户控件,用于设置文本框的文本。这个字符串can是多线的。
我注意到,在某些具有文本属性的控件上,您不会被迫在单行属性文本框中键入内容,而是会弹出一个小窗口,您可以在其中键入多行内容。 (事实上,Windows 窗体文本框控件允许在 Text 属性上执行此操作。)
如何在我设计的属性的属性窗口中启用此功能?
以下不是我的应用程序中的真实代码,而是如何定义此类属性的示例
public string Instructions
{
get
{
return TextBox1.Text;
}
set
{
TextBox1.Text = value;
}
}
您可以使用EditorAttribute with a MultilineStringEditor:
[EditorAttribute(typeof(MultilineStringEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Instructions
{
get
{
return TextBox1.Text;
}
set
{
TextBox1.Text = value;
}
}
为了避免添加对 System.Design 的引用并因此需要完整框架,您还可以像这样编写属性:
[EditorAttribute(
"System.ComponentModel.Design.MultilineStringEditor, System.Design",
"System.Drawing.Design.UITypeEditor")]
尽管现在这不再是一个问题,因为他们已经停止将框架分为客户配置文件和完整的框架。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)