ActiveReports allows you to apply a page template to an existing report by using the Overlay method.
This walkthrough illustrates how to overlay an ActiveReport with a "letterhead" page template.
This walkthrough is split up into the following activities:
- Adding two ActiveReports to a Visual Studio project
- Connecting the report to a data source
- Adding controls to both reports
- Adding code to the Windows Form Load event to set the viewer document equal to the report document and to overlay the report pages with the "letterhead" template
- Viewing the report
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.
When you have completed this walkthrough, you will have a report that looks similar to the following.
Adding two ActiveReports to a Visual Studio project
To add two ActiveReports to a Visual Studio project
- Open a new project in Visual Studio.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptReport.
- Click Open.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptTemplate.
- Click Open.
Connecting the main report to a data source
To connect rptReport to a data source
- Click on the gray report DataSource icon in the Detail section of rptReport to open the report DataSource dialog.
- Select the "OLE DB" tab.
- Click the Build button.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to continue.
- In the Query field, type "Select * from customers order by country".
- Click OK to return to the report design surface.
Adding controls to display the data
To add controls to rptReport
- Select the page header section, and set the Height property to 0.4. (This will match the height of the page header in the template.)
- Add a GroupHeader/Footer section by right-clicking the report and selecting Insert > GroupHeader/Footer.
- Make the following changes to the group header:
- Change the Name property to ghCustomers
- Change the BackColor property to MediumSlateBlue
- Change the CanShrink property to True
- Change the DataField property to Country
- Add labels with the following properties to ghCustomers:
Font Style Name Text Section Location Bold lblCustomerID Customer ID GroupHeader 0, 0 Bold lblCompanyName Company Name GroupHeader 0.94, 0 Bold lblAddress Address GroupHeader 2.44, 0 Bold lblCity City GroupHeader 4.63, 0 Bold lblCountry Country GroupHeader 5.69, 0 - Make the following changes to the detail section:
- Change the BackColor property to LightGray
- Change the CanShrink property to True
- In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the detail section and set the following properties of each textbox as indicated.
Field Text Size Location CustomerID Customer ID 0.88, 0.19 0, 0 CompanyName CompanyName 1.44, 0.19 0.94, 0 Address Address 2.13, 0.19 2.44, 0 City City 1, 0.19 4.63, 0 Country Country 0.8, 0.19 5.69, 0
To add controls to rptTemplate
- Make the following changes to the page header:
- Change the BackColor property to DarkSlateBlue
- Change the Height property to 0.4
- Add labels with the following properties to the page header:
Font Name Text ForeColor Location Size = 18
Style=Bold
lblCompanyName Company Name White 0, 0 Size = 16
Style=Bold
lblCompanyLogo (Company Logo) White 4.69, 0 - Make the following changes to the page header:
- Change the BackColor property to DarkSlateBlue
- Add a label with the following properties to the page footer:
Miscellaneous Name Text ForeColor Location Alignment = Center
Style = Bold
Size = 6.5, 0.2
lblCompanyInfo Company Address, Phone Number, Fax Number, URL White 0, 0
Adding code to the Windows Form Load event
To write the code in Visual Basic or 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 document equal to the rptReport report document
- Apply the "letterhead" template page to rptReport by using the Overlay() method
The following example shows what the code for the Overlay() method looks like.
' Visual Basic
Private Sub myForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _ MyBase.Load Dim rpt As New rptReport() rpt.Run() Viewer1.Document = rpt.Document Dim rpt2 As New rptTemplate() rpt2.Run() For i = 0 To rpt.Document.Pages.Count - 1 rpt.Document.Pages(i).Overlay(rpt2.Document.Pages(0)) Next End Sub //C# private void myForm_Load(object sender, System.EventArgs e) { rptReport rpt = new rptReport(); rpt.Run(); viewer1.Document = rpt.Document; rptTemplate rpt2 = new rptTemplate(); rpt2.Run(); for(int i = 0; i < rpt.Document.Pages.Count; i++) { rpt.Document.Pages[i].Overlay(rpt2.Document.Pages[0]); } }
Viewing the report
To view the report
- Press F5 to run the project and view the report.
![]() |
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer. |