Allow multi-line String properties in the Properties window

后端 未结 1 1254
小鲜肉
小鲜肉 2020-12-10 15:05

I\'ve got a Windows Form User Control with a string property for setting the text of a textbox. This string can be multi-line.

I\'ve noticed that on some c

相关标签:
1条回答
  • 2020-12-10 15:36

    You can use the EditorAttribute with a MultilineStringEditor:

    [EditorAttribute(typeof(MultilineStringEditor), 
                     typeof(System.Drawing.Design.UITypeEditor))]  
    public string Instructions
    {
       get
       {
          return TextBox1.Text;
       }
       set
       {
          TextBox1.Text = value;
       }
    }
    

    To avoid adding a reference to System.Design and thus requiring the Full framework, you can also write the attribute like this:

    [EditorAttribute(
        "System.ComponentModel.Design.MultilineStringEditor, System.Design",
        "System.Drawing.Design.UITypeEditor")]
    

    Although this is less of a problem now that they've stopped splitting the framework into a Client Profile and a Full one.

    0 讨论(0)
提交回复
热议问题