c# - 在“属性”窗口中允许多行字符串属性

标签 c# visual-studio-2008 windows-forms-designer

我有一个带有字符串属性的 Windows 窗体用户控件,用于设置文本框的文本。这个字符串可以是多行的。

我注意到,在某些具有文本属性的控件上,您不会被迫在单行属性文本框中键入内容,而是会弹出一个小窗口,您可以在其中键入多行内容。 (事实上​​,Windows 窗体文本框控件在 Text 属性上允许这样做。)

如何在我设计的属性的属性窗口中启用此功能?

以下不是我应用中的真实代码,而是如何定义此类属性的示例

public string Instructions
{
   get
   {
      return TextBox1.Text;
   }
   set
   {
      TextBox1.Text = value;
   }
}

最佳答案

您可以使用 EditorAttributeMultilineStringEditor :

[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/

相关文章:

sql-server - Visual Studio 2008 中的 "This server version is not supported.Only Up To Microsoft SQL server 2005 are supported"无法连接到 SQL Server 2008 R2

c# - 如何在 Visual Studio 输出窗口中运行控制台应用程序,而不是打开新的命令提示符?

c# - ASP.net 登录控件帮助

c# - 以编程方式继承 C# Windows 窗体应用程序中的表

c# - 为什么我们在实现 iNotifyPropertyChanged 时检查 PropertyChanged 事件是否为空值?

c# - 为 serilog sink 指定更高的日志级别

c# - MVC 模型验证多 View

c# - 试图将从多个函数返回的 "similar looking"元组映射到一个变量

c# - Windows 窗体/控件中 *.resx 文件的相关性是什么?

c# - 如何在继承的ControlDesigner类中获取ITypeDescriptorContext和IServiceProvider