我有一个带有字符串属性的 Windows 窗体用户控件,用于设置文本框的文本。这个字符串可以是多行的。
我注意到,在某些具有文本属性的控件上,您不会被迫在单行属性文本框中键入内容,而是会弹出一个小窗口,您可以在其中键入多行内容。 (事实上,Windows 窗体文本框控件在 Text 属性上允许这样做。)
如何在我设计的属性的属性窗口中启用此功能?
以下不是我应用中的真实代码,而是如何定义此类属性的示例
public string Instructions
{
get
{
return TextBox1.Text;
}
set
{
TextBox1.Text = value;
}
}
最佳答案
您可以使用 EditorAttribute
用MultilineStringEditor
:
[EditorAttribute(typeof(MultilineStringEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Instructions
{
get
{
return TextBox1.Text;
}
set
{
TextBox1.Text = value;
}
}
为避免添加对 System.Design 的引用并因此需要 Full 框架,您还可以这样编写属性:
[EditorAttribute(
"System.ComponentModel.Design.MultilineStringEditor, System.Design",
"System.Drawing.Design.UITypeEditor")]
虽然现在他们已经停止将框架拆分为客户端配置文件和完整配置文件,但这不是什么大问题。
关于c# - 在“属性”窗口中允许多行字符串属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1711880/