简体   繁体   中英

How to make a property appear in the property grid for a control that i created?

I've created a control that have some properties i am trying to add the properties to the Property Grid, Also how to choose the Control that edits the property's value in the property grid

Thanks

Are you instantiating your control on a form or another control in the Visual Studio designer? You should be able to view an edit all properties, such as strings or boolean values, as long as those properties are public and have a get/set accessor.

To customize how the properties appear on the property grid, you can use attributes such as DefaultValue.

I have no idea what you mean by the second half of your sentence. The control that sets the properties is always the parent control when using the Visual Studio designer.

You add propery's to the designer by using attributes from System.ComponentModel.CategoryAttribute which is found in the System.ComponentModel Namespace.

using System.ComponentModel;

[Category("Layout"), Description("Your Description Here"), DefaultValue(true)]
bool  yourPropertyName
{
    .....
}   

This will put your property in the Layout Category of your Property grid with a description of "Your Description Here" with a DefaultValue of true . If you do not assign a Category your Property will be assigned to the Misc. Category by default if your are in category view.

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