ActiveReports Developer can be used to print any label size by using the newspaper column layout.
This walkthrough illustrates how to create a report that repeats labels using the LayoutAction property and prints labels to a laser printer. The labels in this example are 1" x 2.5" and print 30 labels per 8½" x 11" sheet.
The walkthrough is split up into the following activities:
- Connecting the report to a data source
- Adding controls to the report to display data
- Adding code to the detail_Format event to repeat labels
- Viewing the report
Note: This walkthrough uses the Northwind database. By default, in ActiveReports, the NWind.mdb file is located in the [User Documents folder]\ComponentOne Samples\ActiveReports Developer 7\Data folder. |
When you have finished this walkthrough, you get a report that looks similar to the following at design time and at runtime.
Design Time Layout
Runtime Layout
To add an ActiveReport to the Visual Studio project
- Create a new Visual Studio project.
- From the Project menu, select Add New Item.
- In the Add New Item dialog that appears, select ActiveReports 7 Section Report (code-based) and in the Name field, rename the file as rptLabels.
- Click the Add button to open a new section report in the designer.
See Adding an ActiveReport to a Project for information on adding different report layouts.
To connect the report to a data source
- On the detail section band, click the Data Source Icon.
- In the Report Data Source dialog that appears, on the OLE DB tab, next to Connection String, click the Build button.
- 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.
- 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.
- Click the Test Connection button to see if you have successfully connected to the database.
- 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.
- In the Query field on the OLE DB tab, enter the following SQL query.
SQL Query Copy Code SELECT ContactName, CompanyName, Address, City, PostalCode, Country FROM Customers - Click OK to save the data source and return to the report design surface.
To create a layout for the report
- Right-click the PageHeader section and select Delete to remove the PageHeader and Footer sections from the report.
- In the Report menu, select Settings and change the margins as follows:
- Top margin: 0.5
- Bottom margin: 0.5
- Left margin: 0.2
- Right margin: 0.2
- In the Report Explorer, select Report and in the Properties Window, set the PrintWidth property to 8.1 (the width of the label sheet less the Left and Right margins).
- Click the detail section of the report to select it and in the Properties window, set the properties as follows.
Property Name Property Value CanGrow False ColumnCount 3 ColumnDirection AcrossDown ColumnSpacing 0.2 Height 1 - From the toolbox, drag six TextBox controls onto the detail section and set the properties of each textbox as follows.
Property Name Property Value DataField ContactName Location 0, 0 in Size 2.5, 0.2 in Font Bold True Property Name Property Value DataField CompanyName Location 0, 0.2 in Size 2.5, 0.2 in Property Name Property Value DataField Address Location 0, 0.4 in Size 2.5, 0.2 in Property Name Property Value DataField City Location 0, 0.6 in Size 2.5, 0.2 in Property Name Property Value DataField PostalCode Location 0, 0.8 in Size 1.45, 0.2 in Property Name Property Value DataField Country Location 1.5, 0.8 in Size 1, 0.2 in - Select all of the textboxes, and in the Properties Window, set the CanGrow property to False. This prevents overlapping text, but may crop data if one of the fields contains more data than the control size allows.
If you preview the report at this point, one copy of each label appears on the page.
To add code to the detail_Format event to repeat labels
- Double-click in the detail section to create a detail_Format event.
- Add the following code to the event to repeat each label across all three columns.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Format event. | Copy Code |
---|---|
'print each label three times Static counter As Integer counter = counter + 1 If counter <= 2 Then Me.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout Or GrapeCity.ActiveReports.LayoutAction.PrintSection Else Me.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout Or GrapeCity.ActiveReports.LayoutAction.NextRecord Or GrapeCity.ActiveReports.LayoutAction.PrintSection counter = 0 End If |
C# code. Paste JUST ABOVE the Format event. | Copy Code |
---|---|
int counter=0; |
C# code. Paste INSIDE the Format event. | Copy Code |
---|---|
//print each label three times counter = counter + 1; if (counter <= 2) { this.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout|GrapeCity.ActiveReports.LayoutAction.PrintSection; } else { this.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout|GrapeCity.ActiveReports.LayoutAction.NextRecord|GrapeCity.ActiveReports.LayoutAction.PrintSection; counter = 0; } |
- Click the preview tab to view the report at design time.
OR
- Open the report in the Viewer. See Using the Viewer for further information.