Glossary Item Box
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).
To add an ActiveReport to your project
To connect the report to a data source
To add controls to the report
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 |
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 |
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();
}
To view the report
See Also |
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.