This example demonstrates two custom controls. For each control there is a custom "brick" class, and a custom "brick exporter" class.
Control | Brick | Brick Exporter | |
---|---|---|---|
Class | XRRoundLabel | RoundLabelBrick | RoundLabelBrickExporter |
Base Class | XRLabel | LabelBrick | LabelBrickExporter |
Control | Brick | Brick Exporter | |
---|---|---|---|
Class | XRRoundPanel | RoundPanelBrick | RoundLabelBrickExporter |
Base Class | XRPanel | PanelBrick | PanelBrickExporter |
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.
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".
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.
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.
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.
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.
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:
- XRRoundLabel
- RoundLabelBrick
- RoundLabelBrickExporter
- XRRoundPanel
- RoundPanelBrick
- RoundLabelBrickExporter
- RoundedBorderPaintHelper
- RoundedCustomControl.cs
- CustomControlToolBoxRegistrator.cs
- Create a Custom Numeric Label
- Create a Custom Progress Bar Control
- Add a Custom Control to the End-User Report Designer Toolbox (WPF)
- Custom Report Control in the Web End User Designer Toolbox (ASP.NET Web Forms)
- Custom Report Control in the Web End User Designer Toolbox (ASP.NET MVC)
- Custom Report Control in the Web End User Designer Toolbox in ASP.NET Core Application