How to: Complete Windows Forms Print Jobs

 

Frequently, word processors and other applications that involve printing will provide the option to display a message to users that a print job is complete. You can provide this functionality in your Windows Forms by handling the EndPrint event of the PrintDocument component.

The following procedure requires that you have created a Windows-based application with a PrintDocument component on it, which is the standard way of enabling printing from a Windows-based application. For more information about printing from Windows Forms using the PrintDocument component, see How to: Create Standard Windows Forms Print Jobs.

To complete a print job

  1. Set the DocumentName property of the PrintDocument component.

    printDocument1.DocumentName = "MyTextFile";  
    
    
    
  2. Write code to handle the EndPrint event.

    In the following code example, a message box is displayed, indicating that the document has finished printing.

    private void printDocument1_EndPrint(object sender,   
    System.Drawing.Printing.PrintEventArgs e)  
    {  
       MessageBox.Show(printDocument1.DocumentName +   
          " has finished printing.");  
    }  
    
    
    

    (Visual C# and Visual C++) Place the following code in the form's constructor to register the event handler.

    this.printDocument1.EndPrint += new  
       System.Drawing.Printing.PrintEventHandler  
       (this.printDocument1_EndPrint);  
    
    
    

PrintDocument
Windows Forms Print Support

Show: