views:

155

answers:

1

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;
   }
}
+3  A: 

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;
   }
}
najmeddine
Sorry, I must be missing some references. I am not getting the MiltilineStringEditor as an option in my Intellisense. Even when I use System.ComponentModel.Design.MultilineStringEditor. And it won't compile. If I ca get it to work, I'll give you the credit for the right answer, though...
David Stratton
you have to reference `System.Design.dll`
najmeddine
Perfect. I found that out on my own and was just coming back to post that as a comment. Thank you. I'm going to keep this open for a day or so so that hopefully you will get some votes on the answer beside my own. This was a pretty obscure piece of knowledge, and I think you should be rewarded.
David Stratton
glad it was helpful. Thanks.
najmeddine
Adding a reference to System.Design requires that the target framework is not Client Profile but Full. As an alternative, write the attribute like this: `[EditorAttribute("System.ComponentModel.Design.MultilineStringEditor, System.Design", "System.Drawing.Design.UITypeEditor")]` - this works with the Client Profile too!
romkyns