C#: Use Design Time Property in a User Component

person Jason Huangfolder_openC#, Codelocal_offer, , , access_time September 3, 2016

Normally, you can not set design time property within a user control. Design time means when you drag and drop a user component on your windows form, you can see the properties grid, that allow you to set the properties of a component.

In order to make certain properties of your user control visible in properties grid during design time, you will have to add some attributes to your definition of properties.

For example: this is an example of simple property for a text box, that sets a prompt value.

        [Description("Prompt for entering some text"), Category("Data")]
        public string Prompt
                PromptText = value;
                this.Text = value;
                return this.Text;

Note: you must have a get block for this property, otherwise this property will not show up in design time.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>