ActiveReports 14 .NET Edition
ActiveReports 14 User Guide / Samples and Walkthroughs / Walkthroughs / Section Report Walkthroughs / Layout / Overlaying Reports (Letterhead)
In This Topic
    Overlaying Reports (Letterhead)
    In This Topic

    ActiveReports allows you to overlay static report formats over data reports. This walkthrough illustrates how to overlay an ActiveReport with a static letterhead report.

    This walkthrough is split up into the following activities:

    Note: This walkthrough uses the Northwind database. The NWIND.mdb file can be downloaded from GitHub: ..\Samples14\Data\NWIND.mdb.

    When you complete this walkthrough you get a layout that looks similar to the following at design time and at run time.

    Design-Time Layout (rptLetterhead)

    Letterhead at design time

    Letterhead at design time

    Design-Time Layout (rptData)

    Overlaying report at design time

    Overlaying report at design time

    Run-Time Layout

    Overlaying report at run time

    Overlaying report at run time

    To add an ActiveReport to the Visual Studio project

    1. Create a new Visual Studio project.
    2. From the Project menu, select Add New Item.
    3. In the Add New Item dialog that appears, select ActiveReports 14 Section Report (code-based) and in the Name field, rename the file as rptLetterhead.
    4. Click the Add button to open a new section report in the designer.
    5. From the Project menu, select Add New Item.
    6. In the Add New Item dialog that appears, select ActiveReports 14 Section Report (code-based) and in the Name field, rename the file as rptData.
    7. Click the Add button to open a new section report in the designer.

    See Quick Start for information on adding different report layouts.

    To connect the rptData to a data source

    1. On the detail section band, click the Data Source Icon.
      Data Source Icon
    2. In the Report Data Source dialog that appears, on the OLE DB tab, next to Connection String, click the Build button.
    3. In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button to move to the Connection tab.
    4. Click the ellipsis (...) button to browse to your database, for example the NWind.mdb sample database. Click Open once you have selected the appropriate database path.
    5. Click the Test Connection button to see if you have successfully connected to the database.
    6. Click OK to close the Data Link Properties window and return to the Report Data Source dialog. Notice that the Connection String field gets filled automatically.
    7. In the Query field on the OLE DB tab, enter the following SQL query.
      SQL Query
      Copy Code
      SELECT * FROM Customers ORDER BY Country
    8. Click OK to save the data source and return to the report design surface.

    To create a layout for the rptData

    1. Select the PageHeader section and in the Properties Window, set the Height property to 0.65. (This will match the height of the page header in the template.)
    2. On the design surface, select the grey area outside the report and in the Properties window, set the PrintWidth property to 6.5.
    3. Right-click the report and select Insert > GroupHeader/Footer to add group header and group footer sections.
    4. Select the group header and in the Properties window, set the properties as follows.
      Property Name Property Value
      Name ghCustomers
      BackColor MediumSlateBlue
      CanShrink True
      DataField Country
      GroupKeepTogether FirstDetail
      KeepTogether True
    5. From the toolbox, drag the following controls to ghCustomers and in the Properties window, set the properties as follows.

      TextBox1

      Property Name Property Value
      DataField ="Customers in " + Country
      (DataField)
      Size 2, 0.2 in
      Location 0, 0 in
      Font Bold True
      ForeColor White
      Font Size 12

      Label1

      Property Name Property Value
      Text ID
      Size 0.6, 0.2 in
      Location 0, 0.2 in
      Font Bold True
      ForeColor DarkSlateBlue

      Label2

      Property Name Property Value
      Text Company Name
      Size 1.1, 0.2 in
      Location 0.7, 0.2 in
      Font Bold True
      ForeColor DarkSlateBlue

      Label3

      Property Name Property Value
      Text Address
      Size 1, 0.2 in
      Location 2.7, 0.2 in
      Font Bold True
      ForeColor DarkSlateBlue

      Label4

      Property Name Property Value
      Text City
      Size 1, 0.2 in
      Location 5.5, 0.2 in
      Font Bold True
      ForeColor DarkSlateBlue
    6. Click the Detail section and in the Properties window, set the properties as follows.
      Property Name Property Value
      BackColor LightGray
      CanShrink True
    7. From the toolbox, drag four TextBox controls onto the Detail section and set the properties of each textbox as follows.

      TextBox1

      Property Name Property Value
      DataField CustomerID
      Size 0.6, 0.2 in
      Location 0, 0 in

      TextBox2

      Property Name Property Value
      DataField CompanyName
      Size 2, 0.2 in
      Location 0.7, 0 in

      TextBox3

      Property Name Property Value
      DataField Address
      Size 2.8, 0.2 in
      Location 2.7, 0 in

      TextBox4

      Property Name Property Value
      DataField City
      Size 1, 0.2 in
      Location 5.5, 0.2 in
    8. Select the group footer and in the Properties window, set the Height property to 0

    To create a layout for the rptLetterhead

    1. Select the Page Header and in the Properties window, set the properties as follows.
      Property Name Property Value
      BackColor DarkSlateBlue
      Height 0.65
    2. From the toolbox, drag a Label control onto the Page Header and in the Properties window, set the properties as follows.

      Label1

      Property Name Property Value
      Size 6.5, 0.65 in
      Location 0, 0 in
      Font Size 36
      Font Bold True
      ForeColor White
      Text GrapeCity
    3. Select the Page Footer and in the Properties window, set the BackColor property to DarkSlateBlue.
    4. From the toolbox, drag a Label control onto the Page Footer and in the Properties window, set the properties as follows.
      Property Name Property Value
      Size 6.5, 0.2 in
      Location 0, 0 in
      Alignment Center
      Font Bold True
      ForeColor White
      Text 984-242-0700, https://www.grapecity.com/activereportsnet,
      us.sales@grapecity.com

    To add code to overlay the data report pages with the letterhead report

    To write the code in Visual Basic.NET

    • Add the ActiveReports viewer control to the Windows Form. Then, double-click the top of the Windows Form to create an event-handling method for the form's Load event. Add code to the handler to:
      • Set the viewer to display the rptData report document
      • Overlay rptLetterhead on rptData

    The following example shows what the code for the method looks like.

    Visual Basic.NET code. Paste INSIDE the Form Load event.
    Copy Code
       Dim rpt As New rptData()
       rpt.Run()     
       Dim rpt2 As New rptLetterhead()
       rpt2.Run()
       Dim i As Integer
       For i = 0 To rpt.Document.Pages.Count - 1
          rpt.Document.Pages(i).Overlay(rpt2.Document.Pages(0))
       Next
       Viewer1.Document = rpt.Document
    

    To write the code in C#

    • Add the ActiveReports viewer control to the Windows Form. Then, double-click the top of the Windows Form to create an event-handling method for the form's Load event. Add code to the handler to:
      • Set the viewer to display the rptData report document
      • Overlay rptLetterhead on rptData

    The following example shows what the code for the method looks like.

    C# code. Paste INSIDE the Form Load event.
    Copy Code
       rptData rpt = new rptData();
       rpt.Run();
       rptLetterhead rpt2 = new rptLetterhead();
       rpt2.Run();
       for(int i = 0; i < rpt.Document.Pages.Count; i++)
       {
          rpt.Document.Pages[i].Overlay(rpt2.Document.Pages[0]);
       }
       viewer1.Document = rpt.Document;
    
    

    To view the report

    Open the report in the Viewer. See Windows Forms Viewer for further information.