Free Resources from FMS

Additional Resources

 

Thank you! Thank you! I just finished reading this document, which was part of a link in the recent Buzz newsletter. I have printed it for others to read, especially those skeptical on the powers of Access and its capabilities.

Darren D.

 

Free Catalog

 

Customizing the Way Custom Properties Show in the Properties Window

Provided by: Molly Pell, Technical Project Manager

Overview

The .NET Framework makes it simple to create customized and reusable controls. Using .NET, component developers have more flexibility than ever—user controls can inherit the attributes of existing Windows Forms or other user controls, or they can be designed from scratch. This increased flexibility and ease-of-use offers the unique opportunity to reuse code in the form of objects, and is increasing the popularity of custom controls. However as with any reusable code, user controls must be well designed to be compelling. A well-designed user control not only gives the run-time user what they need (through its graphical user interface), but is also easy for developers to use in design time.

When you define a property, it is important to determine whether the property values should be editable at design time (using the Windows Forms Properties Window) and if so, to display it properly. Use the functions in the System.ComponentModel namespace to customize the way user control properties show in the Properties Window.

Browsable Attribute

Use the System.ComponentModel.Browsable attribute to specify whether the property shows in the Properties Window. The Properties Window shows properties that have no Browsable attribute or have the attribute set to True.
If a property is not appropriate for design time editing, set the Browsable attribute to False.

Example:

    ' VB

    <System.ComponentModel.Browsable(False)> _
        Public Property Steps() As Integer
        Get
            Return m_MySteps
        End Get
        Set(ByVal Value As Integer)
            m_MySteps = Value
            Me.Invalidate()
        End Set
    End
Property

    // C#
    [System.ComponentModel.Browsable(false)]
    public int Steps
    {
          get
          {
                return m_Steps;
          }
          set
          {
                m_Steps = value;
                this.Invalidate();
          }
    }

Description Attribute

Use the System.ComponentModel.Description attribute to specify the descriptive text that shows at the bottom of the Properties Window. This text should be concise yet descriptive enough to explain the purpose of the property.

For instance, the Button control’s BackColor property’s description is: “The background color used to display text and graphics in the control.”
 

Example:

    ' VB
    <System.ComponentModel.Description("Number of steps between the start and end values.")> _
        Public Property Steps() As Integer
        Get
            Return m_MySteps
        End Get
        Set(ByVal Value As Integer)
            m_MySteps = Value
            Me.Invalidate()
        End Set
    End
Property
 

      // C#
      [System.ComponentModel.Description("Number of steps between the start and end values.")]
      public int Steps
      {
            get
            {
                  return m_Steps;
            }
            set
            {
                  m_Steps = value;
                  this.Invalidate();
            }
      }

Category Attribute

Use the System.ComponentModel.Category attribute to specify the name of the category in which the property should be displayed in the Properties Window. For instance, the Button control’s BackColor property is displayed in the Appearance category.

Example:

    ' VB
    <System.ComponentModel.Category("Gradient")> _
       Public Property Steps() As Integer
        Get
            Return m_MySteps
        End Get
        Set(ByVal Value As Integer)
            m_MySteps = Value
            Me.Invalidate()
        End Set
    End
Property

    // C#
    [System.ComponentModel.Category("Gradient")]
    public int Steps
    {
          get
          {
                return m_Steps;
          }
          set
          {
                m_Steps = value;
                this.Invalidate();
          }
    }

ParenthizePropertyName Attribute

Use the System.ComponentModel.ParenthizePropertyName attribute to specify whether the property name is displayed with parentheses in the Properties Window. Use parenthesis to force the property to appear at the top of the sort order (near the top of the list when sorted alphabetically, or near the top of the category when in categorized mode).

Example:

    ' VB
    <System.ComponentModel.ParenthesizePropertyName(False)> _
        Public Property Steps() As Integer
        Get
            Return m_MySteps
        End Get
        Set(ByVal Value As Integer)
            m_MySteps = Value
            Me.Invalidate()
        End Set
    End
Property

    // C#
    [System.ComponentModel.ParenthesizePropertyName(false)]
    public int Steps
    {
          get
          {
                return m_Steps;
          }
          set
          {
                m_Steps = value;
                this.Invalidate();
          }
    }

 

Return to the tips page