Glossary Item Box

Tasks: Using the ActiveReports WinForm Viewer

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

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 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 (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. Click on File > 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. Open a new project in Visual Studio.
  2. Click on Project > Add New Item.
  3. Select ActiveReports file and rename the file rptLabels.
  4. Click Open.

Connecting the data source to a database

To connect the data source to a database

  1. Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. Click on Build...
  3. Select "Microsoft Jet 4.0 OLE DB Provider" and click Next >>.
  4. Click on the ellipsis to browse for the access path to Nwind.mdb. Click Open once you have selected the appropriate access path.
  5. Click OK to continue.
  6. In the Query field, type "Select ContactName, CompanyName, Address, City, PostalCode, Country FROM Customers".
  7. 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
  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. Set the PrintWidth of the report to the width of the label sheet less the Left and Right margins, or 8.1"
  4. Make the following changes to the Detail section:
    • 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 in
    • Set the height of the Detail section to the height of the label, 1"
  5. Add the following controls to the Detail section:
  6. Control DataField Name Text/Caption Location
    TextBox ContactName txtContactName Contact Name 0, 0
    TextBox CompanyName txtCompanyName Company Name 0, 0.198
    TextBox Address txtAddress Address 0, 0.396
    TextBox City txtCity City 0, 0.594
    TextBox PostalCode txtPostalCode Zip Code 0, 0.792
    TextBox Country txtCountry Country 1.5, 0.792

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 go to the Detail_Format event
  2. Add the following code to the event to repeat each label across all three columns.
    ' Visual Basic
    Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
    	Detail.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 a Windows Form.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports WinForm Viewer for help.

Tasks: Using the ActiveReports WinForm Viewer

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.