ActiveReports for .NET 3 Online Help Request technical support
Address Labels
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Basic > Address Labels

Glossary Item Box

ActiveReports can be used to print any label size by using the newspaper column layout.

This walkthrough illustrates how to create a report that prints labels to a laser printer labels sheet and to repeat labels using the LayoutAction property. 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:

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 finished this walkthrough, you will have a report that looks similar to the following.

Creating a new Visual Studio project

To create a new Visual Studio project

  1. Open Visual Studio.
  2. From the File menu, select New > Project.

  3. Select the project type and click on Windows Application.
  4. Change the name of your project and click OK.

Adding an ActiveReport to a Visual Studio project

To add an ActiveReport to your project

  1. From the Project menu, select Add New Item.
  2. Select ActiveReports 3.0 File and rename the file rptLabels.
  3. Click Open.

Connecting the data source to a database

To connect the data source to a database

  1. Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. Select the "OLE DB" tab. 
  3. Click the Build button.
  4. Select "Microsoft Jet 4.0 OLE DB Provider" and click Next.
  5. Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to continue.
  7. In the Query field, type "Select ContactName, CompanyName, Address, City, PostalCode, Country FROM Customers".
  8. Click OK to return to the report design surface.

Adding controls to contain data

To add controls to the report

  1. Remove the PageHeader and Footer sections from the report by right-clicking in the PageHeader section and selecting "Delete."
  2. In the Report menu, click Settings and change the margins as follows:
    • Top margin: 0.5
    • Bottom margin: 0.5
    • Left margin: 0.2
    • Right margin: 0.2
  3. Select rptLabels in the Visual Studio Properties Window and Set the PrintWidth property of the report to 8.1 (the width of the label sheet less the Left and Right margins).
  4. Click on the detail section of the report to select it and make the following changes:
    • Set the CanGrow and CanShrink properties to False
    • Change the ColumnCount property to 3
    • Change the ColumnDirection property to AcrossDown
    • Set the ColumnSpacing property to 0.2
    • Set the height of the Detail section to 1 (the height of the label)
  5. In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the detail section and set the Text and Location properties of each textbox as indicated.
    Field Text Location
    ContactName Contact Name 0, 0
    CompanyName Company Name 0, 0.198
    Address Address 0, 0.396
    City City 0, 0.594
    PostalCode Postal Code 0, 0.792
    Country Country 1.5, 0.792

 

Note: When you drag a field from the Report Explorer onto the design surface of the report, the DataField and Name properties of the textbox object are automatically set to the field. 

Adding code to the detail_Format event to repeat labels

To add code to the the detail_Format event

  1. Double-click in the detail section to create a Detail_Format event
  2. Add the following code to the event to repeat each label across all three columns.
    ' Visual Basic
    Private Sub Detail1_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
    	Detail1.Format
        'print each label three times
        Static counter As Integer
        counter = counter + 1
        If counter <= 2 Then
            Me.LayoutAction = 3
        Else
            Me.LayoutAction = 7
            counter = 0
        End If
    End Sub

    //C# int counter=0; private void detail_Format(object sender, System.EventArgs eArgs) { //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; } }

Viewing the report

To view the report

  1. Add the ActiveReports viewer control to your Windows form and set its Dock property to Fill.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports Windows Form Viewer for help.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer.

See Also

©2009. All Rights Reserved.