displaying descriptions for properties of custom user controls

G

Guest

When one works with the visual designer of VS2005, selecting a Control on a
Form, will display its properties in the Properties pane. Selecting any
property will display both the property name and a description of that
property in a small frame at the bottom of the Properties pane.

My question is: how could I show descriptions for properties of my own
custom user controls? I have added XML documentation comments to the source
code, which I thought would also populate the description in the properties
pane. Am I missing some element in the doc-comment that handles this? Or is
it done with some other mechanism?
 
N

Nicholas Paldino [.NET/C# MVP]

Michael,

You need to attach the Description attribute to the property. You can
find it in the System.ComponentModel namespace.
 
L

Linda Liu [MSFT]

Hi Michael,

As Nicholas has replied, to show descriptions for properties of your own
custom UserControls in the Properties window, you need to add the
DescripitonAttribute to the properties.

The following is a sample.

using System.ComponentModel;

public class UserControl1 : System.Windows.Forms.UserControl
{
[Description("this is the description of my property.")]
public string MyProperty
{....}
}

In addition, the XML document file is generally used with the IntelliSense
feature, which is not relevant to the description text shown in the
Properties window.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks, both. I figured I was missing the right piece of the puzzle. I
observe that the Description attribute even lets you put the property into a
category of your own choice, too. Neat.
 
L

Linda Liu [MSFT]

Hi Michael,

Thank you for your reply.

As for grouping a custom property in a specified category when the property
is displayed in a PropertyGrid, we should use CategoryAttribute to do it.
The DescriptionAttribute can only specify the description text displayed in
a PropertyGrid.

The following is a sample of using the CategoryAttribute.

public partial class UserControl1 : UserControl
{
[Category("My Category")]
public string MyProperty
{ ... }
}

Hope this helps.


Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top