2010-09-21 70 views
0

我正在寫一個自定義的控制進行編輯,我想添加一個String類型的「MessageText中」屬性:.NET 2010的自定義控制,多字符串屬性在設計師

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

的MessageText中屬性多行文本,用戶必須能夠使用設計者設置文本。問題在於設計者不允許直接爲字符串屬性輸入換行符。

我想相同的行爲系統的TextBox的Text屬性,在那裏你可以請單擊向下箭頭,寫在出現的小文本編輯器行:

我怎麼做?

回答

3

這是TextBoxBase.Text財產申報:

[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.. 
} 

的[編輯]屬性是你所需要的。如果您還使用.NET 4.0(注意版本字符串),則會很麻煩。最好使用構造函數的替代版本。 Project +添加引用,選擇System.Design。看起來像這樣:

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... 
     }