Click here to Skip to main content
15,891,184 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.5K   15.6K   257  
Using the library presented, you can print reports from C# and other .NET languages
// Copyright (c) 2003, Michael Mayer
// See License.txt that should have been included with this source file.
// or see http://www.mag37.com/csharp/articles/Printing/

using System;
using System.Drawing;
using System.Drawing.Printing;

namespace ReportPrinting
{
	/// <summary>
	/// NOT USED YET!
	/// An interface for printable objects.  To be printed, you must
	/// implement this interface
	/// </summary>
	public interface IPrintable
	{

        /// <summary>
        /// Gets the size that will be used on the following call to print
        /// (including margins and/or UseFullHeight / UseFullWidth)
        /// </summary>
        SizeF Size
        {
            get;
        }

        /// <summary>
        /// Gets the actual required size for content 
        /// that will be used on the following call to print
        /// (excluding margins and/or UseFullHeight / UseFullWidth)
        /// </summary>
        SizeF RequiredSize
        {
            get;
        }

        /// <summary>
        /// Gets the boolean flag for if this ReportSection needs
        /// to be continued.
        /// </summary>
        bool Continued
        {
            get;
        }

        /// <summary>
        /// Gets the boolean flag for if this ReportSection 
        /// fits within the bounds at all.
        /// </summary>
        bool Fits
        {
            get;
        }


        /// <summary>
        /// This method is used to perform any required initialization.
        /// </summary>
        /// <param name="g">Graphics object to print on.</param>
        void BeginPrint (
            Graphics g
            );

        /// <summary>
        /// Resets the size values.  This enables
        /// the CalcSize method to be called again.
        /// </summary>
        void ResetSize();


        /// <summary>
        /// Method called to Calculate the size required for
        /// the next Print.  Calling this method should set the
        /// values for RequiredSize, Continued and Fits
        /// </summary>
        /// <param name="reportDocument">The parent ReportDocument that is printing.</param>
        /// <param name="g">Graphics object to print on.</param>
        /// <param name="bounds">Bounds of the area to print within.</param>
        void CalcSize (
            ReportDocument reportDocument,
            Graphics g,
            Bounds bounds);

        /// <summary>
        /// Method called to Print this object.
        /// </summary>
        /// <param name="reportDocument">The parent ReportDocument that is printing.</param>
        /// <param name="g">Graphics object to print on.</param>
        /// <param name="bounds">Bounds of the area to print within.</param>
        void Print (
            ReportDocument reportDocument,
            Graphics g,
            Bounds bounds);
	}
}

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