ActiveReports 9 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Section Report Walkthroughs > Layout > Address Labels |
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:
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 9\Data folder. |
When you have finished this walkthrough, you get a report that looks similar to the following at design time and at runtime.
To add an ActiveReport to the Visual Studio project
See Adding an ActiveReport to a Project for information on adding different report layouts.
To connect the report to a data source
SQL Query |
Copy Code
|
---|---|
SELECT ContactName, CompanyName, Address, City, PostalCode, Country FROM Customers |
To create a layout for the report
Property Name | Property Value |
---|---|
CanGrow | False |
ColumnCount | 3 |
ColumnDirection | AcrossDown |
ColumnSpacing | 0.2 |
Height | 1 |
TextBox1
Property Name | Property Value |
---|---|
DataField | ContactName |
Location | 0, 0 in |
Size | 2.5, 0.2 in |
Font Bold | True |
TextBox2
Property Name | Property Value |
---|---|
DataField | CompanyName |
Location | 0, 0.2 in |
Size | 2.5, 0.2 in |
TextBox3
Property Name | Property Value |
---|---|
DataField | Address |
Location | 0, 0.4 in |
Size | 2.5, 0.2 in |
TextBox4
Property Name | Property Value |
---|---|
DataField | City |
Location | 0, 0.6 in |
Size | 2.5, 0.2 in |
TextBox5
Property Name | Property Value |
---|---|
DataField | PostalCode |
Location | 0, 0.8 in |
Size | 1.45, 0.2 in |
TextBox6
Property Name | Property Value |
---|---|
DataField | Country |
Location | 1.5, 0.8 in |
Size | 1, 0.2 in |
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
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 |
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 = 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; } |
To view the report
OR