Glossary Item Box
ActiveReports can be used to create a base class as a template from which other reports can inherit. A very simple example of how this functionality may be used is the creation of a company letterhead template. To do this, create a LetterHead class with code like the following.
[C#]
using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Document;
namespace InheritanceCS
{
/// <summary>
/// Summary description for LetterHead.
/// The LetterHead class is to be used with reports having only a Detail section.
/// </summary>
public class LetterHead : ActiveReport //Tell the letterhead class to inherit from AR
{
public LetterHead()
{
//
// TODO: Add constructor logic here
//
}
protected void InitializeLetterhead()
{
//create sections and controls for the letterhead
PageHeader ph = new PageHeader();
PageFooter pf = new PageFooter();
Picture p = new Picture();
Label l = new Label();
Label l2 = new Label();
//set properties on sections and controls
ph.BackColor = System.Drawing.Color.Gainsboro;
ph.Height = 1F;
pf.BackColor = System.Drawing.Color.Gainsboro;
pf.Height = 1F;
p.Name = "Logo";
p.Image = System.Drawing.Image.FromFile(@"c:\logo.gif");
p.Left = 0F;
p.Width = 2.5F;
l.Name = "CompanyName";
l.Text = "Data Dynamics Ltd.";
l.Left = 2.5F;
l.Width = 4F;
l.Height = 1F;
l.Font = new System.Drawing.Font("Times New Roman", 20);
l2.Name = "WebsiteAddress";
l2.Text = "http://www.datadynamics.com";
l2.Left = 0F;
l2.Width = 6.5F;
l2.Alignment = TextAlignment.Center;
//add the sections created above to the report
this.Sections.Insert(0,ph);
this.Sections.Insert(2,pf);
//add the controls created above to the sections
ph.Controls.Add(p);
ph.Controls.Add(l);
pf.Controls.Add(l2);
}
protected void rptLetter_ReportStart(object sender, System.EventArgs eArgs)
{
//add the code in InitializeLetterhead to the ReportStart event
//of the report
InitializeLetterhead();
}
}
}
[Visual Basic]
Imports System
Imports DataDynamics.ActiveReports
Imports DataDynamics.ActiveReports.Document
Namespace InheritanceVB
Public Class Letterhead
Inherits ActiveReport 'Tell the letterhead class to inherit from AR
Protected Sub InitializeLetterhead()
'The Letterhead class is for use with reports containing only a Detail section.
'create sections and controls for the letterhead
Dim ph As PageHeader = New PageHeader
Dim pf As PageFooter = New PageFooter
Dim p As Picture = New Picture
Dim l As Label = New Label
Dim l2 As Label = New Label
'set properties on sections and controls
With ph
.BackColor = System.Drawing.Color.Gainsboro
.Height = 1.0F
End With
With pf
.BackColor = System.Drawing.Color.Gainsboro
.Height = 1.0F
End With
With p
.Name = "Logo"
.Image = System.Drawing.Image.FromFile("c:\logo.gif")
.Left = 0.0F
.Width = 2.5F
End With
With l
.Name = "CompanyName"
.Text = "Data Dynamics Ltd."
.Left = 2.5F
.Width = 4.0F
.Height = 1.0F
.Font = New System.Drawing.Font("Times New Roman", 20)
End With
With l2
.Name = "WebsiteAddress"
.Text = "http://www.datadynamics.com"
.Left = 0.0F
.Width = 6.5F
.Alignment = TextAlignment.Center
End With
'add the sections created above to the report
Me.Sections.Insert(0, ph)
Me.Sections.Insert(2, pf)
'add the controls created above to the sections
ph.Controls.Add(p)
ph.Controls.Add(l)
pf.Controls.Add(l2)
End Sub
Protected Sub rptLetter_ReportStart(ByVal sender As Object, ByVal eArgs As System _
.EventArgs)
'add the code in InitializeLetterhead to the ReportStart event of the report
InitializeLetterhead()
End Sub
End Class
End Namespace
Then in the code behind any report that is to inherit from this class, change the inheritance in the automatically generated code from "ActiveReport" to your class name, in this case "LetterHead." To use the code in the ReportStart event you created in the class above, create an event handler just after InitializeReport() with code like the following.
[C#] this.ReportStart += new EventHandler(base.rptLetter_ReportStart);
[Visual Basic] AddHandler Me.ReportStart, AddressOf rptLetter_ReportStart
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.