Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / Visual Basic

Printing Reports in .NET

Rate me:
Please Sign up or sign in to vote.
4.85/5 (70 votes)
26 Aug 2008CPOL11 min read 440.9K   15.6K   257  
Using the library presented, you can print reports from C# and other .NET languages
using System;
using System.Drawing;
using ReportPrinting;

namespace ReportDocumentTesting
{
	/// <summary>
	/// This class makes use of the Layered container.
	/// That is, each section has access to the full size of the
	/// container, which in this case is the page.
	/// </summary>
	public class ReportTest2 : IReportMaker
	{
        public void MakeDocument(ReportDocument reportDocument)
        {
            TextStyle.ResetStyles();

            // We'll add a background to the normal style
            TextStyle.Normal.BackgroundBrush = Brushes.Beige;


            // Start a layout of layers - each section is layed out without
            // regard to previous sections.  It is, in fact, on a layer above.
            // We'll use parameters of the ReportSection to set where each
            // of nine text sections are printed.
            ReportBuilder builder = new ReportBuilder(reportDocument);
            builder.StartLayeredLayout(true, true);

            string text = "Proofread carefully\nto see if you\nany words out.";
            SectionText section;

            // The default location of a section if we don't set the values.
            section = builder.AddText(text, TextStyle.Normal);
            //section.HorizontalAlignment = HorizontalAlignment.Left;
            //section.VerticalAlignment = VerticalAlignment.Top;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Center;
            section.VerticalAlignment = VerticalAlignment.Top;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Right;
            section.VerticalAlignment = VerticalAlignment.Top;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Right;
            section.VerticalAlignment = VerticalAlignment.Middle;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Right;
            section.VerticalAlignment = VerticalAlignment.Bottom;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Center;
            section.VerticalAlignment = VerticalAlignment.Bottom;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Left;
            section.VerticalAlignment = VerticalAlignment.Bottom;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Left;
            section.VerticalAlignment = VerticalAlignment.Middle;

            section = builder.AddText(text, TextStyle.Normal);
            section.HorizontalAlignment = HorizontalAlignment.Center;
            section.VerticalAlignment = VerticalAlignment.Middle;

            builder.FinishLayeredLayout();
        }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions