Skip to main content

Lesson 5 - Insert Two Bricks

  • 2 minutes to read

The link created in this lesson generates a document that contains two different bricks.

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e161/reporting-get-started-with-printing-library.

To add a brick to a document created via a printing link, do the following.

  1. To create a new printing link, declare a new class (Lesson5) derived from the Lesson4 class defined in the previous lesson. The new class overrides the CreateDetail method, and provides a virtual CreateRow method that inserts a row consisting of one brick under the previous brick.

    using System.Drawing;
    using DevExpress.XtraPrinting;
    // ...
    
    public class Lesson5 : Lesson4 {
        public Lesson5(PrintingSystem ps) : base(ps) {}
    
        protected override void CreateDetail(BrickGraphics graph) {
            // Center the text string.
            graph.StringFormat = graph.StringFormat.ChangeLineAlignment(StringAlignment.Center);
    
            base.CreateDetail(graph);
            CreateRow(graph);
        }
    
        protected virtual void CreateRow(BrickGraphics graph) {
            // Set the brick font name to 'Arial', set the size to '14', and set the bold attribute.
            graph.Font = new Font("Arial", 14, FontStyle.Bold);
    
            // Add a text brick with all borders to a specific location 
            // containing the "Good-bye!" text in blue font.
            graph.DrawString("Good-bye!", Color.Blue, 
                new Rectangle(0, top += 50, 150, 50), BorderSide.All);
        }
    }
    
  2. Next, modify the main form’s Load event handler to pass the Printing System of the Document Viewer to the new link.

    using System;
    using System.Windows.Forms;
    using DevExpress.XtraPrinting;
    // ...
    
    private void Form1_Load(object sender, System.EventArgs e) {
        Lesson5 lesson = new Lesson5(printingSystem1);
    }
    

Launch the application and view the result.

document-viewer-ribbon-link-document-result-insert-two-bricks

See Also