Allow multiline String properties in the properties window

I have a Windows Form user control with a string property to set the text of a text field. This line can be multi-line.

I noticed that on some controls with a text property, and instead of having to enter a text field with a single line, you pop up a little where you can enter multiple lines. (Essentially, the Windows Forms TextBox control allows this in the Text property.)

How to enable this functionality in the properties window for a property that I developed?

There is no real code in my application, but an example of how such a property can be defined

public string Instructions { get { return TextBox1.Text; } set { TextBox1.Text = value; } } 
+7
c # visual-studio-2008 windows-forms-designer
source share
1 answer

You can use EditorAttribute with MultilineStringEditor :

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

In order not to add a reference to System.Design and, therefore, requiring a complete framework, you can also write an attribute as follows:

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

Despite the fact that now this is not a problem, since they have ceased to separate the structure into the client profile and the full one.

+14
source share

All Articles