Version

BeforePrint Event

Occurs after a print job has been initiated and configured by the user, just before data is sent to the printer.
Syntax
'Declaration
 
Public Event BeforePrint As BeforePrintEventHandler
public event BeforePrintEventHandler BeforePrint
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 BeforePrint event occurs before the report is sent to the printer, but after the user has had the opportunity to configure the print job using the Print and Page Setup dialogs. The Print and Page Setup dialogs can be made available to the user when invoking the Print method, and will contain any default settings you have specified for the print job in the InitializePrint event. The BeforePrint event is the last opportunity you have to change the parameters of a print job before it is committed to the print queue.

You can use the BeforePrint event to programmatically examine any changes to the PrintInfo object resulting from the user's actions. You can then choose to modify the user's settings where appropriate, or store them for later use.

The PrintInfo object is only accessible during this event, the InitializeLogicalPrintPage event, the InitializePrint event and the InitializePrintPreview event.

Example
Following code shows how to print the UltraGrid and makes use of BeforePrint event to show a confirmation dialog before proceeding with printing the UltraGrid.

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.Drawing.Printing

  Private Sub Button16_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button16.Click

      ' Following code shows a print preview dialog and then prints the UltraGrid.

      Try
          ' Optinally show the print preview dialog.
          Me.ultraGrid1.PrintPreview()

          ' Calling print causes the UltraGrid to send the print job to the printer.
          Me.ultraGrid1.Print()
      Catch exc As Exception
          ' Catch any exceptions that may get thrown and let the user know.
          MessageBox.Show("Error occured while printing." & vbCrLf & exc.Message, "Error printing", _
                                      MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try

  End Sub

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

      ' Following code shows a message box giving the user a last chance to cancel printing the 
      ' UltraGrid.
      Dim result As DialogResult = MessageBox.Show("Proceed with printing ?", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
      If DialogResult.Cancel = result Then e.Cancel = True

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

private void button16_Click(object sender, System.EventArgs e)
{	

	// Following code shows a print preview dialog and then prints the UltraGrid.

	try
	{
		// Optinally show the print preview dialog.
		this.ultraGrid1.PrintPreview( );

		// Calling print causes the UltraGrid to send the print job to the printer.
		this.ultraGrid1.Print( );			
	}
	catch ( Exception exc )
	{
		// Catch any exceptions that may get thrown and let the user know.
              
		MessageBox.Show( "Error occured while printing.\n" + exc.Message, "Error printing", 
			MessageBoxButtons.OK, MessageBoxIcon.Error );
	}

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

	// Following code shows a message box giving the user a last chance to cancel printing the 
	// UltraGrid.

	DialogResult result = MessageBox.Show( "Proceed with printing ?", "Confirm", 
		MessageBoxButtons.OKCancel, MessageBoxIcon.Question );
	
	if ( DialogResult.Cancel == result )
		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