How to create a custom DevExpress report control (below)

Download DevExpress v20.1 full version     DevExpress v20.1 Chinese resource acquisition

DevExpress Technical Exchange Group 2: 775869749 Welcome to join the group discussion

DevExpress Winforms Controls has  built-in more than 140 UI controls and libraries, perfect to build smooth, beautiful and easy-to-use applications. Want to experience? Click to download>>

This article records how to build a custom DevExpress Report control (Swiss QR-Bill report component) and how to solve the problems encountered in the development process. I hope that this information will be valuable to users who create a custom DevExpress Report control.

To help eliminate the mystery in the development of report controls, this article describes how to create design-time settings, serialization designer components and related "bricks", and how to render and print components. The first part contains general information about the Swiss QR Bill control and describes the requirements of the control itself; the second part details the implementation of the component.

"Brick" realization

General concept

VisualBrick is the basic element for displaying data. The VisualBrick element consists of a data model (the brick) and its representation (the exporter).

Exporter renders and exports it to different formats, using the BrickExporter (Type) property of the "brick" setting to specify "brick". In this article, we use PanelBrickExporter and VisualBrickExporter descendants as exporters. The Draw method is rewritten to implement rendering, and the Brick field is used to obtain access to "brick".

To create a "brick", please override the CreateBrick(VisualBrick[] childrenBricks) method and return the "brick" instance. PutStateToBrick(VisualBrick brick, PrintingSystemBase ps) method maps control properties to "brick" data. Please check the code in the following file for more information: XRSwissQRBill.cs .

Basic class selection

The Swiss QR Control layout is an area with text elements and barcodes in the middle. The main choices for the basic category are panels, tables and text "brick". Panel "brick" can arrange components inside through its simple results, so SwissQRBillBrick is based on PanelBrick class, and exporter is based on PanelBrickExporter class.

Implement Service Brick

The specification states that the payment section may contain blank areas marked with corners. In order to meet this requirement, we created an additional CornerRectangleBrick and its exporter-CornerRectangleBrickExporter-it is responsible for drawing corners, "brick" includes BrickType property-this property can be overridden to achieve correct deserialization.

Layout realization

Select PanelBrick as the basic class, you can use the Bricks property to access its internal "bricks", relative to the coordinates of the panel itself-set the internal "brick" coordinates relative to the point (0, 0).

The components are divided into receiving and payment areas.

The rendering function returns other "bricks" (or "brick" combinations), which are then added to the Bricks collection.

  • CreateReceiptPart()
  • CreatePaymentPart()

Now, we must render the subregion.

  1. CreateReceiptTitle()
  2. CreateReceiptInformation()
  3. CreateReceiptAmount()
  4. CreateReceiptAcceptancePoint()
  5. CreatePaymentTitle()
  6. CreatePaymentSwissQRCode()
  7. CreatePaymentAmount()
  8. CreatePaymentInformation()
  9. CreatePaymentFurtherInformation()

Please check the code in the following file for more information: SwissQRBillBrick.cs .

Exporter implementation

The exporter draws decorations on the finished "brick", which makes it possible to change the appearance in the previewed or exported PDF file. In this article, the exporter draws perforation lines and other text. The SeparatorKind option of brick determines the content to be drawn. It is used to preview and use the same mechanism of drawing "brick" during the PDF export process. The main difference lies in the Draw method passed to the exporter. IGraphics is an object with the IPdfGraphics interface.

Serialization

General concept

Both control and "brick" need to be serialized, "brick" only uses xml serialization, and the control implements xml serialization and supports CodeDom serialization-this is necessary for Visual Studio Designer.

Control serialization

The XtraSerializableProperty attribute is responsible for serializing the attributes in the xml. Only specify the attributes to serialize and return simple types of attributes. Complex types need to have a constructor of the XtraSerializationVisibility parameter type (the most commonly used values ​​are Hidden, Collection, Reference, Content).

The DesignerSerializationVisibility property is responsible for the CodeDOM serialization in Visual Studio Designer. It has only three variants of related enumerations-hidden, visible and content. The collection or reference is marked with the visible property value. The DefaultValue property determines whether the property value is included in the serialization.

Brick serialization

Only XML serialization is required. In order to deserialize correctly, map the "brick's" text type (BrickType attribute overridden at the Brick level) to the real type. The BrickFactory.BrickResolve method is used for mapping. To implement the BrickResolve method, please view the code in the following file: CustomControl.cs

Component usage

To use components in Visual Studio Designer, add them to Visual Studio Toolbox.

To use this component in the end-user designer, use the passed XRDesignMdiController as a parameter to call the AddSwissQRControlToToolBox method. Please check the code in the following file for more information: CustomControlToolBoxRegistrator.cs

Get first-hand DevExpress consultation, all on DevExpress Chinese website!

Guess you like

Origin blog.csdn.net/AABBbaby/article/details/108482839