The System.ComponentModel namespace (more information here) in .Net contains an array of various attributes that every .Net developer should know about. These attributes provide a way for the developer to implement design-time and run-time behavior on both controls and components. In addition to attributes, this namespace also has base classes, interfaces, binding sources, etc.
By using the various attributes in this namespace you can create better, more useable UI controls for your projects. Below are a few that I tend to use often.
BrowsableAttribute - (more info here)
This is a boolean attribute and when set to false, the property on the control will not show up in the Properties panel in the IDE. This is nice when you want to have a property but not expose it at design time to the developer.
CategoryAttribute - (more info here)
This is a simple attribute that will take a string and will allow you to create a custom category for your control. If you do not use this, your control property will show up in the 'Misc' category in the Properties panel in the IDE.
DefaultValueAttribute - (more info here)
This attribute will all you to set the default value for the property in the control itself. This will also show the default value in the Properties panel in the IDE.
NOTE - This WILL NOT work if you also are using the DesignOnly attribute.
DescriptionAttribute - (more info here)
This is another simple property that will allow the author of the control to provide description text about the meaning of the property. This is similar to adding comments to the code, but it will be displayed in the Properties panel in the IDE.
DesignOnlyAttribute - (more info here)
This is a boolean attribute that is great. You this and set it to true if you have a property that you DO NOT WANT to be set with any type of default value in the designer generated code. Adding this can save you a ton of time and effort.
NOTE - My experience has shown me that this will supercede the DefaultValue attribute is this is set to true.
ReadOnlyAttribute - (more info here)
This attribute is just a way to mark the property as read only. This can also be accomplished by NOT putting a setter on the property.
Till next time,
01-30-2008 7:03 AM