Custom Controls Design Time Support Part 2: More Design Time Attributes

In my previous post I pointed out the most common used Attributes for Design Time Support. In this part I will point out some more Attributes that take advantage of the Design Time Environment.

Attributes Applied To Description
DisplayName Properties & Events Specifies the display name for a property or an event.
ParenthesizeProperty Properties  Indicates whether the name of the associated property is displayed with parentheses in the Properties window.
RefreshProperties Properties Indicates that the property grid should refresh when the associated property value changes.
NotifyParentProperty Properties Indicates that the parent property is notified when the value of the property that this attribute is applied to is modified.
ReadOnly Properties Specifies whether the property this attribute is bound to is read-only or read/write.
DesignOnly Properties

Specifies whether a property can only be set at design time.

[more] 

» DisplayNameAttribute is useful when you need the name displayed in the PropertyWindow different than property actual name.

[code:c#]

[DisplayName("Number of Clicks")]
public int NumOfClicks

[/code]

DisplayNameAttribute 

» ParenthesizePropertyAttribute when you have a special property such as Name and need it to appear between brackets this is the attribute to use.

[code:c#]

[ParenthesizePropertyName(true)]
public string SpecialProperty

[/code]

» RefreshPropertiesAttribute when you have property's value which depends on the value of another one then you will need this attribute, mark the property that when changed should refresh others with this attribute.

[code:c#]

[RefreshProperties(RefreshProperties.All)]
public string RefreshOtherProperty

[/code]

» NotifyParentPropertyAttribute Apply this one to a property if its parent property should receive notification of changes to the property's values. For example, the Size property has two nested properties: height and width. These nested properties should be marked with NotifyParentPropertyAttribute(true) so they notify the parent property to update its value and display when the property values change.

[code:c#]

[NotifyParentProperty(true)]
public string NotifyparentProperty

[/code]

» ReadOnlyAttribute When applying this attribute with parameter true then it will be unchangable in the design time, this is different than making a property without a set accessor since properties marked with ReadOnlyAttribute can be changed using code.

[code:c#]

[ReadOnly(true)]
public string ReadOnlyProperty

[/code]

» DesignOnlyAttribute from the name implies that the property marked with this attribute will only be available in the design mode.

[code:c#]

[DesignOnly(true)]
public string DesignTimeOnlyProperty

[/code]

ButtonEx.cs (3.36 kb)


Posted

in

,

by

Tags:

Comments

3 responses to “Custom Controls Design Time Support Part 2: More Design Time Attributes”

  1. Amr Avatar

    Hello IG,
    About the DateTime property by default will have a custom Editor which shows a DateTimePicker control to allow the user(developer) to pick a Date, however might need to have more flexibility and control on how that DateTimePicker works or even change it, you will need to build a custom UITypeEditor, I will be covering this in my next few posts so be tuned.

  2. IG Avatar

    Thanks Amr for the detailed representation.
    I have a question about the design time support for custom controls.
    I had a property that is of type DateTime, and I wanted the user to be able to set it from the properties panel at the design time, as when the user can find a button which shows the calendar control, where the user choses a date. I dont want the silly textbox that appears where the user can type in anything he likes. just the same way when you make an enum property, you will find the enum values there at the design time in the properties panel. Any help?

  3. IG Avatar

    ok great… thanks dude 🙂

Leave a Reply

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