Glossary Item Box

Samples | Walkthroughs

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

Walkthrough: Scaling Pages

This walkthrough illustrates how to set scaling to print a report.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the NorthWind database (NWind.mdb).

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 rptScale.
  4. Click Open.

Connecting the report to a data source

To connect the report to a data source

  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 * from categories INNER JOIN products ON categories.categoryID = products.categoryID order by products.categoryid".
  7. Click OK to return to the report design surface.

Adding controls to the report to contain data

To add controls to the report

  1. Add a GroupHeader/Footer section to rptScale.
  2. Make the following changes to the group header:
    • Change the name to ghProducts
    • Change the DataField property to CategoryName
    • Change the GroupKeepTogether property to FirstDetail
    • Change the KeepTogether property to True
  3. Add the following controls to the GroupHeader section:

    Control DataField Name Text/Caption Location
    TextBox CategoryName txtCategoryName Category Name 0, 0
    Label (Empty string) lblProductName Product Name 0, 0.3125
    Label (Empty string) lblUnitsInStock Units In Stock 2.125, 0.3125
    Label (Empty string) lblUnitsOnOrder Units On Order 3.25, 0.3125
    Label (Empty string) lblUnitPrice Unit Price 4.375, 0.3125

  4. Add the following controls to the Detail section:

    Control DataField Name Text/Caption Location Output Format
    TextBox ProductName txtProductName Product Name 0, 0 (Empty string)
    TextBox UnitsInStock txtUnitsInStock Units In Stock 2.125, 0 (Empty string)
    TextBox UnitsOnOrder txtUnitsOnOrder Units On Order 3.25, 0 (Empty string)
     
    TextBox UnitPrice txtUnitPrice Unit Price 4.375, 0 Currency

Adding code to the form to set scaling

To write the code in Visual Basic

To write the code in C#

The following example shows what the code looks like.

' Visual Basic
Dim i As Integer
Dim rpt As New rptScale()
Dim m_myARPrinter As New DataDynamics.ActiveReports.Interop.SystemPrinter()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _ MyBase.Load
Viewer1.Document = rpt.Document
rpt.Run()
arScale()
End Sub
Private Sub arScale()
m_myARPrinter.StartJob("Test Printer")
Dim aPage As New DataDynamics.ActiveReports.Document.Page()
Dim rec As New System.Drawing.RectangleF()
Dim xOffSet As Single
Dim yOffSet As Single
Dim adjustedWidth As Single
Dim xPos As Single
xOffSet = m_myARPrinter.PhysicalOffsetX / m_myARPrinter.Graphics.DpiX
yOffSet = m_myARPrinter.PhysicalOffsetY / m_myARPrinter.Graphics.DpiY
adjustedWidth = (aPage.Width / 3) - (xOffSet / 2)
xPos = 0 Dim nCount As Integer
nCount = rpt.Document.Pages.Count
m_myARPrinter.StartPage()
For i = 0 To nCount - 1
aPage = rpt.Document.Pages(i)
m_myARPrinter.Graphics.PageUnit = GraphicsUnit.Pixel
rec = System.Drawing.RectangleF.FromLTRB(xOffSet + xPos, yOffSet, _ (xOffSet + xPos) + adjustedWidth, yOffSet + adjustedWidth)
xPos = adjustedWidth + xPos
aPage.Draw(m_myARPrinter.Graphics, rec)
Next
m_myARPrinter.EndPage()
m_myARPrinter.EndJob()
End Sub
//C#
private void Form1_Load(object sender, System.EventArgs e)
{
rpt = new ActiveReport1();
this.viewer1.Document = rpt.Document;
rpt.Run();
arScale();
}
ActiveReport1 rpt;
DataDynamics.ActiveReports.Document.Page aPage;
private void arScale()
{
aPage = new DataDynamics.ActiveReports.Document.Page();
DataDynamics.ActiveReports.Interop.SystemPrinter m_myARPrinter = new DataDynamics.
ActiveReports.Interop.SystemPrinter();
m_myARPrinter.StartJob("Test Printer");
System.Drawing.RectangleF rec;
float xOffSet = m_myARPrinter.PhysicalOffsetX/m_myARPrinter.Graphics.DpiX;
float yOffSet = m_myARPrinter.PhysicalOffsetY/m_myARPrinter.Graphics.DpiY;
float adjustedWidth = (aPage.Width/3)-(xOffSet*2);
float xPos = 0;
int nCount = rpt.Document.Pages.Count;
m_myARPrinter.StartPage();
for(int i=0; i < nCount; i++)
{
aPage = rpt.Document.Pages[i];
m_myARPrinter.Graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;
rec = System.Drawing.RectangleF.FromLTRB(xOffSet+xPos, yOffSet, (xOffSet+xPos)+ adjustedWidth,yOffSet+adjustedWidth);
xPos = adjustedWidth + xPos;
aPage.Draw(m_myARPrinter.Graphics,rec);
}
m_myARPrinter.EndPage();
m_myARPrinter.EndJob();
}

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.

Samples | Walkthroughs

 

 


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