Version

InitializeLogicalPrintPage Event

Occurs when a logical print page is being formatted for printing or previewing.
Syntax
'Declaration
 
Public Event InitializeLogicalPrintPage As InitializeLogicalPrintPageEventHandler
public event InitializeLogicalPrintPageEventHandler InitializeLogicalPrintPage
Event Data

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

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
Collate Returns the PrintDocument's Collate value (read-only)
Copies Returns the PrintDocument's Copies value (read-only)
DocumentName Returns the PrintDocument's name (read-only)
Landscape Returns the PrintDocument's Landscape value (read-only)
LogicalPageLayoutInfo Layout info of the current logical page
LogicalPageNumber Current logical page number (read-only)
MarginBottom Returns the PrintDocument's Margin Bottom value (read-only). You can set the margins in the InitializePrint and InitializePrintPreview events.
MarginLeft Returns the PrintDocument's Margin Left value (read-only). You can set the margins in the InitializePrint and InitializePrintPreview events.
MarginRight Returns the PrintDocument's Margin Right value (read-only). You can set the margins in the InitializePrint and InitializePrintPreview events.
MarginTop Returns the PrintDocument's Margin Top value (read-only). You can set the margins in the InitializePrint and InitializePrintPreview events.
PaperHeight Returns the PrintDocument's PaperSize Height value (read-only)
PaperWidth Returns the PrintDocument's PaperSize Width value (read-only)
PrintColors Returns the PrintDocument's SupportsColor value (read-only)
PrinterName Returns the PrintDocument's PrinterName value (read-only)
PrintRange Returns the PrintDocument's PrintRange value (read-only)
Remarks

When you print a report using UltraWinGrid, you may find that the data from the grid does not easily fit onto a single sheet of paper. Although this is usually because there are too many rows to fit vertically, it is also possible that your data consists of too many columns to fit horizonatally. For this reason, the control must sometimes make a distinction between a single "logical" page and the "physical" page (or sheets of paper) that may be required to print it. Essentially, logical pages break only on row boundaries. If you print a report with enough columns to fill the widths of three sheets of paper, the first logical page will comprise three physical pages.

The InitializeLogicalPrintPage event occurs whenever the formatting of a new logical page is being calculated in preparation for printing or previewing. You can use the event to make changes to the logical page, such as changing the text of the page header or footer. You can access the settings of the print job (such as the text of the header and footer) by using the properties of LogicalPageLayoutInfo object that is passed into the event via the LogicalPageLayoutInfo parameter.

A common use of this event would be to increment the page number for each page of the report. The LogicalPageNumber parameter passed to the event makes this easy by providing you with the number of the current logical page. Automatic page numbering can be accomplished by setting the PageHeader or PageFooter to a string containing the token <#>. This token will be replaced by the page number.

If you wish to make changes to a print job based on the physical page of a report, you must use the DrawFilter interface.

The LogicalPageLayoutInfo object is only accessible during this event, the BeforePrint event, the IntitializePrint event and the IntitializePrintPreview event. Note that changes made to the print job in the BeforePrint event will cause the InitializeLogicalPrintPage event to occur again.

Example
InitializeLogicalPrintPage is fired for each page that's being printed or previewed. Following code shows some of the information available in the event.

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.UltraWinGrid
Imports System.Diagnostics

   Private Sub UltraGrid1_InitializeLogicalPrintPage(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CancelableLogicalPrintPageEventArgs) Handles ultraGrid1.InitializeLogicalPrintPage

       Debug.WriteLine("e.Collate = " & e.Collate.ToString())
       Debug.WriteLine("e.Copies = " & e.Copies.ToString())
       Debug.WriteLine("e.DocumentName = " & e.DocumentName)
       Debug.WriteLine("e.Landscape = " & e.Landscape)
       Debug.WriteLine("e.LogicalPageNumber = " & e.LogicalPageNumber)
       Debug.WriteLine("e.DocumentName = " & e.MarginBottom)
       Debug.WriteLine("e.DocumentName = " & e.MarginLeft)
       Debug.WriteLine("e.DocumentName = " & e.MarginRight)
       Debug.WriteLine("e.DocumentName = " & e.MarginTop)
       Debug.WriteLine("e.DocumentName = " & e.PaperHeight)
       Debug.WriteLine("e.DocumentName = " & e.PaperWidth)
       Debug.WriteLine("e.DocumentName = " & e.PrintColors)
       Debug.WriteLine("e.DocumentName = " & e.PrinterName)
       Debug.WriteLine("e.DocumentName = " & e.PrintRange)
       Debug.WriteLine("e.DocumentName = " & e.DocumentName)

       ' You can also setup the footer and header on a per page basis.
       e.LogicalPageLayoutInfo.PageHeader = "Page Title"
       e.LogicalPageLayoutInfo.PageHeaderAppearance.ForeColor = Color.DarkGray

       e.LogicalPageLayoutInfo.PageFooter = "Page Footer Text"
       e.LogicalPageLayoutInfo.PageFooterAppearance.TextHAlign = HAlign.Center

       ' Following code cancels the event to prevent prevewing or printing more than 10 pages.
       If e.LogicalPageNumber > 10 Then
           e.Cancel = True
       End If

   End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void ultraGrid1_InitializeLogicalPrintPage(object sender, Infragistics.Win.UltraWinGrid.CancelableLogicalPrintPageEventArgs e)
{

	Debug.WriteLine( "e.Collate = " + e.Collate.ToString( ) );
	Debug.WriteLine( "e.Copies = " + e.Copies.ToString( ) );
	Debug.WriteLine( "e.DocumentName = " + e.DocumentName  );
	Debug.WriteLine( "e.Landscape = " + e.Landscape );
	Debug.WriteLine( "e.LogicalPageNumber = " + e.LogicalPageNumber );
	Debug.WriteLine( "e.DocumentName = " + e.MarginBottom );
	Debug.WriteLine( "e.DocumentName = " + e.MarginLeft );
	Debug.WriteLine( "e.DocumentName = " + e.MarginRight );
	Debug.WriteLine( "e.DocumentName = " + e.MarginTop );
	Debug.WriteLine( "e.DocumentName = " + e.PaperHeight );
	Debug.WriteLine( "e.DocumentName = " + e.PaperWidth );
	Debug.WriteLine( "e.DocumentName = " + e.PrintColors );
	Debug.WriteLine( "e.DocumentName = " + e.PrinterName );
	Debug.WriteLine( "e.DocumentName = " + e.PrintRange );
	Debug.WriteLine( "e.DocumentName = " + e.DocumentName  );

	// You can also setup the footer and header on a per page basis.
	e.LogicalPageLayoutInfo.PageHeader = "Page Title";
	e.LogicalPageLayoutInfo.PageHeaderAppearance.ForeColor = Color.DarkGray;
			
	e.LogicalPageLayoutInfo.PageFooter = "Page Footer Text";
	e.LogicalPageLayoutInfo.PageFooterAppearance.TextHAlign = HAlign.Center;

      // Following code cancels the event to prevent prevewing or printing more than 10 pages.
	if ( e.LogicalPageNumber > 10 )
		e.Cancel = true;

}
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