Other Useful Attributes

DefaultValue is not the only attribute that is useful for properties. The Description attribute is also one that should be used consistently. It contains a text description of the property, and that description shows up at the bottom of the Properties windows when a property is selected. To include a Description attribute, the declaration of the preceding property would appear as follows:


Description("This is a pithy description of my property")> Public Property MyProperty() As Integer

Code snippet from LimitedCheckedListBox


Such a property will look like Figure 15-1 when highlighted in the Properties window.

Another attribute you will sometimes need is the Browsable attribute. As mentioned earlier, a new property appears in the Properties window automatically. In some cases, you may need to create a property for a control that you do not want to show up in the Properties window. In that case, you use a Browsable attribute set to False. Here is code similar to the last, making a property nonbrowsable in the Properties window:

<Browsable(False)> Public Property MyProperty() As Integer

One additional attribute you may want to use regularly is the Category attribute. Properties can be grouped by category in the Properties window by pressing a button at the top of the window. Standard categories include Behavior, Appearance, and so on. You can have your property appear in any of those categories, or you can make up a new category of your own. To assign a category to a property, use code like this:


Public Property MyProperty() As Integer

There are other attributes for control properties that are useful in specific circumstances. If you understand how the common ones discussed here are used, then you can investigate additional attributes for other purposes in the documentation.

0 0

Post a comment