Skip to content

Latest commit

 

History

History
86 lines (53 loc) · 6 KB

File metadata and controls

86 lines (53 loc) · 6 KB

How to Create Controls with Rounded Corners

This example demonstrates two custom controls. For each control there is a custom "brick" class, and a custom "brick exporter" class.

Label with Rounded Corners

Control Brick Brick Exporter
Class XRRoundLabel RoundLabelBrick RoundLabelBrickExporter
Base Class XRLabel LabelBrick LabelBrickExporter

Panel with Rounded Corners

Control Brick Brick Exporter
Class XRRoundPanel RoundPanelBrick RoundLabelBrickExporter
Base Class XRPanel PanelBrick PanelBrickExporter

Implementation

To add a component to the Visual Studio Toolbox, the component must have the a ToolBoxItem(true) attribute.

Design-time functionality is inherited from the base controls.

Each control has the BorderCornerRadius public property that defines the degree to which corners are rounded. The BorderCornerRadius value is used by the RoundedBorderPaintHelper methods to draw background and borders.

"Brick"

The VisualBrick is a basic element used to display data. The VisualBrick element consists of a data model (the brick) and its presentation (the exporter).

The exporter renders the "brick" and exports it to different formats. The exporter is specified with the BrickExporter(Type) attribute set for the "brick". In this example, we use the LabelBrickExporter and PanelBrickExporter descendants as exporters. The DrawBackground methods are overridden to implement rendering. The RoundedBrick property is used to obtain access to the "brick".

Serialization

General Concepts

Both the control and the "brick" require serialization. The "brick" only uses XML serialization, and the control implements XML serialization and supports CodeDom serialization - which is mandatory for the Visual Studio Designer.

Control Serialization

The XtraSerializableProperty attribute is responsible for serializing the property in xml. Specify the attribute to serialize a property that returns a simple type. Complex types require a constructor with a XtraSerializationVisibility argument type. The most frequently used values are the following: Hidden, Collection, Reference, and Content.

The DefaultValue attribute determines whether the property value is included in serialization.

Brick Serialization

Only XML serialization is necessary. For correct deserialization, map the "brick’s" text type (the overridden BrickType property at the Brick level) to the real type. The BrickFactory.BrickResolve method is used for mapping. For an implementation of the BrickResolve method, review the code in the following file: RoundedCustomControl.cs.

Toolbox

To use the component in the Visual Studio Designer, add it to the Visual Studio Toolbox.

To use the component in the End-User Designer, call the AddRoundedLabelToToolBox and AddRoundedPanelToToolBox methods with the XRDesignMdiController instance passed as an argument. Review the code in the following file for more information: CustomControlToolBoxRegistrator.cs.

Result

When you run this project, the XRRoundLabel and XRRoundPanel controls are available in the Toolbox. You can drag-and-drop them to the design area:

Custom Controls with Rounded Corners

Files to Review

Documentation

More Examples