views:

25

answers:

2

I'm writing a custom control and I want to add a "MessageText" property of type String:

<Browsable(True),
  DefaultValue(""),
  Category("CustomControls"),
  Description("Blah."),
  DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  Public Property MessageText As String

The MessageText property is a multiline text, and the user must be able to set the text using the designer. The problem is that the designer doesn't allow to enter a newline directly for a string property.

I want the same behaviour as the system TextBox's Text property, where you can click on the down arrow and write lines in the small text-editor that appears:

How do I do that?

+1  A: 

This is the declaration for the TextBoxBase.Text property:

[Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), Localizable(true)]
public override string Text
{
    // etc..  
}

The [Editor] attribute is what you need. There is hassle if you also use .NET 4.0 (note the version string). It is better to use the alternative version of the constructor. Project + Add Reference, select System.Design. Make it look like this:

using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
...
        [Editor(typeof(System.ComponentModel.Design.MultilineStringEditor), typeof(UITypeEditor))]
        public string MessageText {
            // etc... 
        }
Hans Passant
A: 

Sorry' I've found it:

Editor(GetType(MultilineStringEditor), GetType(Drawing.Design.UITypeEditor))
vulkanino