Attributes

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); }

New to the .NET framework is the concept of attribute-based development. Attributes provide an extensibility mechanism for classes, properties, methods, parameters, and return values. By applying attributes to a particular entity, the default behavior can be altered to produce a new desired result. For a complete description of attributes, refer to the MSDN help.

The .NET designer architecture makes heavy use of attributes to simplify common development tasks. Examples include defining the default value for a property, assigning a category and description to properties, and indicating the default event for a control, to name a few. No discussion of the designer architecture would be complete without a list of attributes commonly used for designers, controls, serialization, licensing, and the PropertyGrid. Table 5.12 lists the attributes found in the System.ComponentModel namespace, along with descriptions.

Table 5.13 and Table 5.14 list the attributes found in the System.ComponentModel.Design.Serialization and System.Drawing namespaces, respectively.

Table 5.12. System.ComponentModel Attributes
Attribute Description
AmbientValueAttribute The value for this property originates for another source, generally the containing control.
BrowsableAttribute Used by the PropertyGrid to determine whether the property should be displayed.
CategoryAttribute Defines the category for the property or event within the PropertyTab of the PropertyGrid.
DefaultEventAttribute Defines the default event for the component.
DefaultPropertyAttribute Defines the default property for a component.
DefaultValueAttribute Defines the default value for a property.
DescriptionAttribute Defines the description for the property or event.
DesignerAttribute Identifies the designer for the specified component.
DesignerCategoryAttribute Defines the category for the designer.
DesignerSeralizationVisibiltyAttribute Specifies how the designer should serialize a property.
DesignOnlyAttribute Specifies that the property is available only at design-time.
EditorAttribute Specifies the UITypeEditor for the component property.
EditorBrowsableAttribute Specifies whether the property is available to the UITypeEditor.
ImmutableObjectAttribute Specifies that the component has no editable properties.
LicenseProviderAttribute Specifies the LicenseProvider for the class.
ListBindableAttribute Specifies a list can be used for data binding.
LocalizableAttribute Localization for a property.
MergablePropertyAttribute Specifies that a property can be combined with properties of other objects in the property window.
NotifyParentPropertyAttribute Specifies that the parent property should be notified when the property is modified.
ParenthesizePropertyNameAttribute Specifies that the property value should appear within a set of parentheses. Example: (Collection) appears next to collection-based properties such as the Tabs property of the Tab control.
PropertyTabAttribute Identifies the property tab(s) to display for the class or classes.
ProvidePropertyAttribute Defines the name of a property provided by the class that implements the IExtenderProvider interface. The ToolTip class is an extender provider.
ReadOnlyAttribute Specifies that the property is read-only within the PropertyGrid.
RecommendedAsConfigurableAttribute Specifies that the property can be used as an application setting.
RefreshPropertiesAttribute Defines how the designer refreshes when the property is modified.
ToolboxItemAttribute Specifies whether the component should be loaded in the toolbox.
ToolboxItemFilterAttribute Specifies that the component will accept only other ToolboxItems belonging to the specified namespace, or type.

Table 5.13. System.ComponentModel.Design.Serialization Attributes
Attribute Description
DesignerSerializerAttribute Indicates the serializer for the serialization manager to use in order to serialize objects of this type.
RootDesignerSerializer Indicates the base serializer for the root object designer.

Table 5.14. System.Drawing Attributes
Attribute Description
ToolboxBitmapAttribute Associates an image with the specified component. Support for small and large images.

Attributes are a prominent theme in .NET development, and custom control development is no exception.



    .NET Windows Forms Custom Controls
    User Interfaces in VB .NET: Windows Forms and Custom Controls
    ISBN: 1590590449
    EAN: 2147483647
    Year: 2002
    Pages: 74

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net