Version

InitializePrint Event

Occurs when a print job is first initiated by invoking the Print method.
Syntax
'Declaration
 
Public Event InitializePrint As InitializePrintEventHandler
public event InitializePrintEventHandler InitializePrint
Event Data

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

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
DefaultLogicalPageLayoutInfo The default layout info, for all logical pages
PrintDocument The print document (read-only)
PrintLayout Returns the print layout.
Remarks

The InitializePrint event occurs when the print job is first initiated via the Print method. It gives you the opportunity to set the default parameters for the print job (number of copies, page orientation, header and footer text, etc.) After you have set up the default print settings in the InitializePrint event, the Page Setup and Print dialogs may be displayed to the end user, depending on the parameters passed to the Print method. The user can change the defaults you have specified through these dialogs. Once the user has completed their changes, the BeforePrint event occurs, giving you the chance to examine the user's settings, change them if necessary or store them for future use.

The PrintInfo object is only accessible during this event, the BeforePrint event, the IntitializePrintPreview event and the InitializeLogicalPrintPage event.

Example
Following code sets some of the properties available in InitializePrint 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

  Private Sub UltraGrid1_InitializePrint(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CancelablePrintEventArgs) Handles ultraGrid1.InitializePrint

      ' One could conditionally set Cancel to true to cancel the printing.
      If Me.CheckBox1.Checked Then
          e.Cancel = True
          Return
      End If

      ' Horizontally fit everything in a signle page.
      e.DefaultLogicalPageLayoutInfo.FitWidthToPages = 1

      ' Set up the header and the footer.
      e.DefaultLogicalPageLayoutInfo.PageHeader = "Title"
      e.DefaultLogicalPageLayoutInfo.PageHeaderHeight = 40
      e.DefaultLogicalPageLayoutInfo.PageHeaderAppearance.FontData.SizeInPoints = 14
      e.DefaultLogicalPageLayoutInfo.PageHeaderAppearance.TextHAlign = HAlign.Center
      e.DefaultLogicalPageLayoutInfo.PageHeaderBorderStyle = UIElementBorderStyle.Solid

      ' Use <#> token in the string to designate page numbers.
      e.DefaultLogicalPageLayoutInfo.PageFooter = "Page <#>."
      e.DefaultLogicalPageLayoutInfo.PageFooterHeight = 40
      e.DefaultLogicalPageLayoutInfo.PageFooterAppearance.TextHAlign = HAlign.Right
      e.DefaultLogicalPageLayoutInfo.PageFooterAppearance.FontData.Italic = DefaultableBoolean.True
      e.DefaultLogicalPageLayoutInfo.PageFooterBorderStyle = UIElementBorderStyle.Solid

      ' Set the ClippingOverride to Yes.
      e.DefaultLogicalPageLayoutInfo.ClippingOverride = ClippingOverride.Yes

      ' Set the document name through the PrintDocument which returns a PrintDocument object.
      e.PrintDocument.DocumentName = "Document Name"

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

private void ultraGrid1_InitializePrint(object sender, Infragistics.Win.UltraWinGrid.CancelablePrintEventArgs e)
{

	// One could conditionally set Cancel to true to cancel the printing.
	if ( this.checkBox1.Checked )
	{
		e.Cancel = true;
		return;
	}

	// Horizontally fit everything in a signle page.
	e.DefaultLogicalPageLayoutInfo.FitWidthToPages = 1;

	// Set up the header and the footer.
	e.DefaultLogicalPageLayoutInfo.PageHeader = "Title";
	e.DefaultLogicalPageLayoutInfo.PageHeaderHeight = 40;
	e.DefaultLogicalPageLayoutInfo.PageHeaderAppearance.FontData.SizeInPoints = 14;
	e.DefaultLogicalPageLayoutInfo.PageHeaderAppearance.TextHAlign = HAlign.Center;
	e.DefaultLogicalPageLayoutInfo.PageHeaderBorderStyle = UIElementBorderStyle.Solid;
	
	// Use <#> token in the string to designate page numbers.
	e.DefaultLogicalPageLayoutInfo.PageFooter = "Page <#>.";
	e.DefaultLogicalPageLayoutInfo.PageFooterHeight= 40;
	e.DefaultLogicalPageLayoutInfo.PageFooterAppearance.TextHAlign = HAlign.Right;
	e.DefaultLogicalPageLayoutInfo.PageFooterAppearance.FontData.Italic = DefaultableBoolean.True;
	e.DefaultLogicalPageLayoutInfo.PageFooterBorderStyle = UIElementBorderStyle.Solid;

	// Set the ClippingOverride to Yes.
	e.DefaultLogicalPageLayoutInfo.ClippingOverride = ClippingOverride.Yes;

	// Set the document name through the PrintDocument which returns a PrintDocument object.
	e.PrintDocument.DocumentName = "Document Name";

}
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