Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow multi-line String properties in the Properties window

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 controls with a text property, and instead of being forced to type in the single line property textbox, you get a little pop up where you can type multiple lines. (As a matter of fact, a Windows Forms Textbox control allows this on the Text property.)

How do I enable this functionality in the properties window for the property I have designed?

The following is not real code in my app, but an example of how such a property might be defined

public string Instructions
{
   get
   {
      return TextBox1.Text;
   }
   set
   {
      TextBox1.Text = value;
   }
}
like image 621
David Avatar asked Nov 10 '09 23:11

David


People also ask

How can you create multi line strings?

Use triple quotes to create a multiline string It is the simplest method to let a long string split into different lines. You will need to enclose it with a pair of Triple quotes, one at the start and second in the end. Anything inside the enclosing Triple quotes will become part of one multiline string.

What are the properties of multiline?

A multiline TextBox allows absolute line breaks and adjusts its quantity of lines to accommodate the amount of text it holds. If needed, a multiline control can have vertical scroll bars. A single-line TextBox doesn't allow absolute line breaks and doesn't use vertical scroll bars.

What is a multiline string?

A multiline string in Python begins and ends with either three single quotes or three double quotes. Any quotes, tabs, or newlines in between the “triple quotes” are considered part of the string. Python's indentation rules for blocks do not apply to lines inside a multiline string.


1 Answers

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.

like image 194
manji Avatar answered Oct 19 '22 22:10

manji