How to create a custom DevExpress report control, you will understand after reading it

Download DevExpress v20.1 full version 

40 minutes to teach you how to get started with DevExpress v20.1, the latest control-Gantt chart, register now >>

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.

General information

Swiss QR Bill is a new type of payment slip with QR code. Swiss QR Bill contains the following elements:

  • receipt
  • Payment part
  • Bar code

The invoice can use the following layout:

  • "Full" invoice printed on A4 paper;
  • "Short" invoice printed on A6 paper;
  • Print invoices continuously;
  • Invoice printed on a single page.

The "full" invoice contains the receipt, while the "empty" invoice only contains payment information. The BillKind property of the component specifies the PaymentAndReceipt value of the complete invoice and the PaymentOnly value of the short-term invoice. Continuous printing or separate printing is specified by the IntegratedMode property.

Print the invoice on A4 or A6 paper (or export to PDF), and specify the perforation line through the BillOption.PreviewSeparatorKind and BillOption.PdfSeparatorKind properties, respectively. This component allows you to change the language and font of any field, and the StringData property can be used to bind the field to an external data source.

Report control development-overview

To create a new report control, you must:

  1. Choose a base class, if you can't find a suitable control derived, please inherit a component from the XRControl class.
  2. Create the object model of the component, specify a set of properties and related properties, these properties determine how to serialize the properties and how to display the properties in the Property grid.
  3. Create component designers for Visual Studio and End User Designer. Designers determine the appearance and operation of components during design, and add attributes as needed.
  4. Select the "brick" of the component. An obvious choice is the building block created by the base class. However, if the component inherits from the XRControl class, there are two options-if you need a simple Brick, select VisualBrick as the base class of the Brick; For the container, select PanelBrick.
  5. Specify how the component creates its "brick" and map the properties of the component to the characteristics of the brick.
  6. Implement the BrickExporter class to present "brick", covering methods for drawing and exporting.

The following sections detail how to build the SwissQRBill component in more detail.

Component realization

Since the SwissQRBill component is a descendant of XRControl, it has its own "brick", serialization, and items in the designer's toolbox.

Design time

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

WinForms End-User Designer requires that the component is registered with IToolBoxService, handles the DesignPanelLoaded event, and then calls the IToolBoxService.AddToolBoxItem method to register the component.

To realize the design-time function of the component, please add Designer and XRDesigner properties for Visual Studio and WinForms End-User Designer respectively. The resizing rules and smart tag items of the control must be modified as needed. The smart tag items are specified by the DesignerActionList object registered in the component designer. The GetSelectionRulesCore method modifies the resizing rules of the control.

When setting up the property grid, pay special attention to expandable objects. In this example, a descendant of ExpandableObjectConverter will be created to override the ConvertTo method. The new ConvertTo method implementation changes the string displayed in the property grid editor. The GetProperties method of AddressTypeConverter deletes unnecessary properties of the address type.


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

Huidu high-end UI interface development

Guess you like

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