Back to Devexpress

PrintingSystemBase.StartPrint Event

corelibraries-devexpress-dot-xtraprinting-dot-printingsystembase-dc5812ef.md

latest6.6 KB
Original Source

PrintingSystemBase.StartPrint Event

Occurs before the printing system’s document is printed.

Namespace : DevExpress.XtraPrinting

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public event PrintDocumentEventHandler StartPrint
vb
Public Event StartPrint As PrintDocumentEventHandler

Event Data

The StartPrint event's data class is PrintDocumentEventArgs. The following properties provide information specific to this event:

PropertyDescription
PrintDocumentGets the object that sends the document’s output to a printer.
PrinterSettingsProvides access to the corresponding printer settings.

Remarks

You can use the StartPrint event to change printing settings just prior to printing the document. Use the e.PrinterSettings property to set up the printer settings.

Consider the following specifics of raising this event from UI for Windows environments:

  • In Windows Forms applications, this event is raised after clicking the Quick Print or Print toolbar button.
  • In WPF applications, this event is raised after clicking the Quick Print toolbar button or the OK button in the Print Dialog.

Example

The following example demonstrates how to use the PrintDocumentEventArgs object when handling the PrintingSystemBase.StartPrint event. The example below demonstrates how to programmatically select a printer to print a document at runtime.

csharp
using System;
using System.Windows.Forms;
using System.Drawing.Printing;
using DevExpress.XtraPrinting;
using DevExpress.Utils;
// ...

// creating a PrintingSystem object
private PrintingSystem printingSystem1 = new PrintingSystem();
//...

private void button1_Click(object sender, System.EventArgs e) {
   // handling the StartPrint event
   printingSystem1.StartPrint += new PrintDocumentEventHandler(printingSystem_StartPrint);

   // printing the document
   printingSystem1.Print();
}

private void printingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {
   // setting the specific printer's name before printing
   e.PrintDocument.PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters[1];
}
vb
Imports System
Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports DevExpress.XtraPrinting
Imports DevExpress.Utils
' ...

' creating a PrintingSystem object
Private WithEvents printingSystem1 As New PrintingSystem()
' ...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
   ' printing the document
   printingSystem1.Print()
End Sub

' handling the StartPrint event
Private Sub printingSystem_StartPrint(ByVal sender As System.Object, _
ByVal e As PrintDocumentEventArgs) Handles printingSystem1.StartPrint
   ' setting the specific printer's name before printing
   e.PrintDocument.PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters(1)
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the StartPrint event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-wpf-override-print-commands/CS/MinimalisticReportPreviewDemo/MyDocumentPreviewControl.cs#L8

csharp
PrintTool pt = new PrintTool(Document.PrintingSystem);
pt.PrintingSystem.StartPrint += new PrintDocumentEventHandler(PrintingSystem_StartPrint);
pt.PrintingSystem.PrintProgress += new PrintProgressEventHandler(PrintingSystem_PrintProgress);

reporting-winforms-print-reports-in-batch/CS/BatchPrinting/Form1.cs#L21

csharp
ReportPrintTool pt1 = new ReportPrintTool(report1);
pt1.PrintingSystem.StartPrint += new PrintDocumentEventHandler(PrintingSystem_StartPrint);

reporting-wpf-override-print-commands/VB/MinimalisticReportPreviewDemo/MyDocumentPreviewControl.vb#L11

vb
Dim pt As PrintTool = New PrintTool(Document.PrintingSystem)
AddHandler pt.PrintingSystem.StartPrint, New PrintDocumentEventHandler(AddressOf PrintingSystem_StartPrint)
AddHandler pt.PrintingSystem.PrintProgress, New PrintProgressEventHandler(AddressOf PrintingSystem_PrintProgress)

reporting-winforms-print-reports-in-batch/VB/BatchPrinting/Form1.vb#L26

vb
Dim pt1 As New ReportPrintTool(report1)
AddHandler pt1.PrintingSystem.StartPrint, AddressOf PrintingSystem_StartPrint

See Also

EndPrint

PrintProgress

Printing and Export in Reporting Tools for Web

PrintingSystemBase Class

PrintingSystemBase Members

DevExpress.XtraPrinting Namespace