简体   繁体   中英

Making a custom control's property input like that of a multiline textbox

Say I have attribute "Address", how can I make it's input in the form designer's property box like that of a text box's text input, like so:

文本框输入图像。

?

Decorate your Address property with an EditorAttribute referencing the MultilineStringEditor class:

using System.ComponentModel;
using System.Drawing.Design;

[Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    typeof(UITypeEditor))]
public string Address
{
    get;
    set;
}

This happens through a "designer". For System.Windows.Forms.TextBox that designer is:

[Designer("System.Windows.Forms.Design.TextBoxDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), SRDescription("DescriptionTextBox"), ComVisible(true), ClassInterface(ClassInterfaceType.AutoDispatch)]

If you want to view its source code, open up .NET Reflector, Open Cache... System.Design, navigate (or search) to System.Windows.Forms.Design.TextBoxDesigner .

UPDATE: Since 2014, the .NET Core is open-source, check out the official repository site

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM