[]
You can use ActiveReports to print any label size by using the newspaper column layout.
These steps show 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 report connects to 'NWIND.db' data source on GitHub.
The final report will look as shown.
In the ActiveReports Designer, create a new Section report.
As you create a new report, the Report Data Source dialog appears for you to configure the report data connection. You can also access this dialog by clicking the DataSource Icon in the Detail section band.
Choose Custom tab > SQLite Provider in the Report Data Source dialog, and bind the report to SQLite data using the following connection string and query.
data source=c:\data\NWIND.db
SELECT ContactName, CompanyName, Address, City, PostalCode, Country FROM Customers
Click OK to close the Report Data Source dialog and return to the report design surface.
Right-click the PageHeader section and select Delete to remove the PageHeader and PageFooter sections from the report.
Go to Report Explorer, right-click the Settings option and select Show to view the Report Settings.
Change the margins as follows:
From the Report Explorer, select Report and in the Properties panel, 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 |
ColumnSpacing | 0.2 |
ColumnDirection | AcrossDown |
Height | 1 |
From the toolbox, drag the following fields one below the other and set the properties of each textbox as follows.
txtContactName1
Property Name | Property Value |
---|---|
DataField | ContactName |
Location | 0, 0 in |
Size | 2.5, 0.2 in |
Font > Bold | True |
txtCompanyName1
Property Name | Property Value |
---|---|
DataField | CompanyName |
Location | 0, 0.2 in |
Size | 2.5, 0.2 in |
txtAddress1
Property Name | Property Value |
---|---|
DataField | Address |
Location | 0, 0.4 in |
Size | 2.5, 0.2 in |
txtCity1
Property Name | Property Value |
---|---|
DataField | City |
Location | 0, 0.6 in |
Size | 2.5, 0.2 in |
txtPostalCode1
Property Name | Property Value |
---|---|
DataField | PostalCode |
Location | 0, 0.8 in |
Size | 1.45, 0.2 in |
txtCountry1
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 Panel, 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.
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.
Imports GrapeCity.ActiveReports.SectionReportModel
'print each label three times
Static counter As Integer
counter = counter + 1
If counter <= 2 Then
rpt.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout Or
GrapeCity.ActiveReports.LayoutAction.PrintSection
Else
rpt.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout Or
GrapeCity.ActiveReports.LayoutAction.NextRecord Or
GrapeCity.ActiveReports.LayoutAction.PrintSection
counter = 0
End If
using GrapeCity.ActiveReports.SectionReportModel;
int counter=0;
//print each label three times
counter = counter + 1;
if (counter <= 2)
{
rpt.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout|
GrapeCity.ActiveReports.LayoutAction.PrintSection;
}
else
{
rpt.LayoutAction = GrapeCity.ActiveReports.LayoutAction.MoveLayout|
GrapeCity.ActiveReports.LayoutAction.NextRecord|
GrapeCity.ActiveReports.LayoutAction.PrintSection;
counter = 0;
}
Improve the appearance of the report and preview.