Editor Style and StyleControllers
- 4 minutes to read
Every editor in the ExpressEditors Library allows you to adjust its appearance in various states via its Style members. The Style, StyleDisabled, StyleFocused and StyleHot properties correspond to a specific editor’s state: the normal, disabled, focused and hot-tracked state respectively. Each property contains different attributes controlling the appearance and the look & feel of an editor in a particular state. The Styles properties’ type depends on the editor type. The TcxCustomEditStyle class is the base class for style classes. TcxCustomEditStyle descendants of this class publish additional properties specific to particular editors.
Each Style member specifies various settings which control the appearance of the editor elements such as: border color, border and button styles, background color, font attributes, look & feel etc.
Default Style Settings
The Style.LookAndFeel property determines the default appearance of an editor. It provides three attributes: NativeStyle, Kind, and SkinName. NativeStyle is applicable only to Windows® XP and Windows® Vista and represents a Boolean value indicating whether editor elements are drawn using the current Windows® theme. If NativeStyle is set to True, most of the other style attributes are ignored. The Kind property specifies the default appearance of your editor if it is not drawn using a Windows® theme. It represents an enumeration of predefined default styles, which can be applied to the editor. To apply skins, use the SkinName property.
Style Attributes and Assigned Values
To redefine the default editor’s appearance in each state, you just need to assign appropriate style attributes. But you can revert to their default values at any moment by calling the TcxCustomEditStyle.RestoreDefaults method. This method clears all modifications in style attributes, if any, and restores the default values. At design time, you can restore style attributes for every state by right-clicking the editor and selecting the Restore styles option from the context menu.
The AssignedValues property represents a set of Boolean flags each of which indicates whether a particular style attribute has been assigned. The following image demonstrates the Object Inspector window for a TcxTextEdit control with its BorderStyle attribute set to ebs3D. The AssignedValues property contains the BorderStyle flag as a specific value was assigned to BorderStyle.
The RestoreDefaults method not only reverts to default values, but also clears all flags in the AssignedValues set. You can clear a specific flag in AssignedValues to restore the default value of an individual style attribute.
Style Controller
A style controller is a separate component, which can be used when necessary to apply a set of style settings to multiple editors. Place a TcxEditStyleController instance onto a form, assign its style attributes as needed and connect the style controller to your editors by setting their TcxCustomEditStyle.StyleController property. For instance, by setting the style controller’s Style property which corresponds to the style which will be applied to editors in the normal state, you can specify style attributes’ values for all editors that are connected to this controller. The properties assigned in this way are tracked by the style controller’s AssignedValues property. Note that new attribute values are applied only for the editor’s properties which have default values as an editor’s style settings have a higher priority than the settings of a style controller. Thus they override the settings of a linked style controller, if assigned.
Default Style Controller
A default style controller is a separate component, which can be used to apply a set of style settings to all editors that have no style controllers. Place a TcxDefaultEditStyleController instance onto a form and assign its Style, StyleDisabled, StyleFocused and StyleHot properties which correspond to various editor states as necessary. Set the TcxDefaultEditStyleController component’s properties to set new style attributes. Unlike the TcxEditStyleController component, you need not connect a default style controller to editors as its style settings are automatically applied to all editors that have no style controllers assigned (i.e. have their TcxCustomEditStyle.StyleController property unassigned). Note that a style controller’s style settings (if it is connected to an editor) have a higher priority than the settings of a default style controller. But an editor’s style settings has a higher priority than the style controller’s ones and override them, if assigned. If a particular style attribute is not assigned either in an editor style or in a style controller, editors will use the default value of this attribute as specified by a default style controller (if any).