ActiveReports 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:
Tip: For basic steps like adding a report to a Visual Studio project and viewing a report, please see the Basic Data Bound Reports walkthrough. |
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).
When you have finished this walkthrough, you will have a report that looks similar to the following.
SQL Query |
Copy Code |
---|---|
SELECT ContactName, CompanyName, Address, City, PostalCode, Country FROM Customers |
Note: When you drag a field from the Report Explorer onto the design surface of the report, the DataField, Name and Text properties of the textbox object are automatically set to txtFieldName1. |
Detail fields
Field | Font | Size | Location |
---|---|---|---|
ContactName | Font Bold = True | 2.5, 0.2 | 0, 0 |
CompanyName | leave at default | 2.5, 0.2 | 0, 0.198 |
Address | leave at default | 2.5, 0.2 | 0, 0.396 |
City | leave at default | 2.5, 0.2 | 0, 0.594 |
PostalCode | leave at default | 1.45, 0.2 | 0, 0.792 |
Country | leave at default | leave at default | 1.5, 0.792 |
If you preview the report at this point, one copy of each label appears on the page.
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 = LayoutAction.MoveLayout Or LayoutAction.PrintSection Else Me.LayoutAction = LayoutAction.MoveLayout Or LayoutAction.NextRecord Or LayoutAction.PrintSection counter = 0 End If |
To write the code in C#
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 = LayoutAction.MoveLayout|LayoutAction.PrintSection; } else { this.LayoutAction = LayoutAction.MoveLayout|LayoutAction.NextRecord|LayoutAction.PrintSection; counter = 0; } |