Version

PageBodyPrinting Event

Fired before the PageBody is rendered
Syntax
'Declaration
 
Public Event PageBodyPrinting As PageBodyPrintingEventHandler
public event PageBodyPrintingEventHandler PageBodyPrinting
Event Data

The event handler receives an argument of type PageBodyPrintingEventArgs containing data related to this event. The following PageBodyPrintingEventArgs properties provide information specific to this event.

PropertyDescription
Document (Inherited from Infragistics.Win.Printing.PageSectionPrintEventArgs)Returns the document that is being rendered.
Graphics (Inherited from Infragistics.Win.Printing.PageSectionPrintEventArgs)Returns the graphics object into which the page should be rendered
Handled Returns or sets whether the default rendering should occur for the page background and border.
PageSettings (Inherited from Infragistics.Win.Printing.PageSectionPrintEventArgs)Returns the System.Drawing.Printing.PageSettings associated with the current page being printed.
RectInsideBorders (Inherited from Infragistics.Win.Printing.PageSectionPrintEventArgs)Returns the area of the section within its borders
RectInsideMargins (Inherited from Infragistics.Win.Printing.PageSectionPrintEventArgs)Returns the area of the section within its margins
RectInsidePadding (Inherited from Infragistics.Win.Printing.PageSectionPrintEventArgs)Returns the area of the section inside the borders.
RectOverall (Inherited from Infragistics.Win.Printing.PageSectionPrintEventArgs)Returns the area available for the section.
Section Returns the section representing the page body.
Example
The following example demonstrates how to use the PageBodyPrinting and PagePrinted events to insert pages into the print operation.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.Printing

    Private Sub UltraSchedulePrintDocument1_PageBodyPrinting(ByVal sender As Object, ByVal e As Infragistics.Win.Printing.PageBodyPrintingEventArgs) Handles UltraSchedulePrintDocument1.PageBodyPrinting
        ' when the first page is printed, prevent the regular
        ' page body from being printed
        If CType(sender, UltraPrintDocument).PageNumber = 1 Then
            'mark the event as handled so page body of the print document will
            'not be rendered
            e.Handled = True

            ' the title page will have a gray background
            e.Graphics.FillRectangle(Brushes.LightGray, e.RectInsidePadding)

            Dim sf As StringFormat = Nothing
            Dim font As Font = Nothing

            Try
                sf = New StringFormat(StringFormatFlags.FitBlackBox)
                sf.Alignment = StringAlignment.Center
                sf.LineAlignment = StringAlignment.Center

                Dim text As String = "Infragistics Win\nPrinting Demo"

                font = New Font("Tahoma", 36.0F)

                e.Graphics.DrawString(text, font, Brushes.Black, RectangleF.op_Implicit(e.RectInsidePadding), sf)
            Finally
                'clean up
                If Not font Is Nothing Then font.Dispose()

                If Not sf Is Nothing Then sf.Dispose()
            End Try
        End If
    End Sub

    Private Sub UltraSchedulePrintDocument1_PagePrinted(ByVal sender As Object, ByVal e As Infragistics.Win.Printing.PagePrintedEventArgs) Handles UltraSchedulePrintDocument1.PagePrinted
        'note: the reprintpage must be honored by the print document and therefore
        'is implementation dependant
        e.ReprintPage = CType(sender, UltraPrintDocument).PageNumber = 1
    End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.Printing;

		private void ultraSchedulePrintDocument1_PageBodyPrinting(object sender, Infragistics.Win.Printing.PageBodyPrintingEventArgs e)
		{
			// when the first page is printed, prevent the regular
			// page body from being printed
			if (((UltraPrintDocument)sender).PageNumber == 1)
			{
				// mark the event as handled so page body of the print document will
				// not be rendered
				e.Handled = true;

				// the title page will have a gray background
				e.Graphics.FillRectangle(Brushes.LightGray, e.RectInsidePadding);

				using (StringFormat sf = new StringFormat(StringFormatFlags.FitBlackBox))
				{
					sf.Alignment = StringAlignment.Center;
					sf.LineAlignment = StringAlignment.Center;
				
					string text = "Infragistics Win\nPrinting Demo";

					using (Font font = new Font("Tahoma", 36f))
						e.Graphics.DrawString(text, font, Brushes.Black, e.RectInsidePadding, sf);
				}
			}
		}

		private void ultraSchedulePrintDocument1_PagePrinted(object sender, Infragistics.Win.Printing.PagePrintedEventArgs e)
		{
			//note: the reprintpage must be honored by the print document and therefore
			//is implementation dependant
			e.ReprintPage = ((UltraPrintDocument)sender).PageNumber == 1;
		}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also