PrintPageEventArgs Class

PrintPageEventArgs Class


Provides data for the PrintPage event.

Namespace:   System.Drawing.Printing
Assembly:  System.Drawing (in System.Drawing.dll)


Public Class PrintPageEventArgs
	Inherits EventArgs

System_CAPS_pubmethodPrintPageEventArgs(Graphics, Rectangle, Rectangle, PageSettings)

Initializes a new instance of the PrintPageEventArgs class.


Gets or sets a value indicating whether the print job should be canceled.


Gets the Graphics used to paint the page.


Gets or sets a value indicating whether an additional page should be printed.


Gets the rectangular area that represents the portion of the page inside the margins.


Gets the rectangular area that represents the total area of the page.


Gets the page settings for the current page.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

The MarginBounds property retrieves the rectangular area that represents the portion of the page between the margins. The PageBounds property retrieves the rectangular area that represents the total area of the page. The Graphics property defines the graphics object with which to do the painting. The PageSettings property retrieves the printer settings for the current page. The remaining properties indicate whether a print job should be canceled or whether a print job has more pages.

For more information about printing with Windows Forms, see the System.Drawing.Printing namespace overview. If you wish to print from a Windows Presentation Foundation application, see the System.Printing namespace.

The following code example assumes a Button named printButton and a PrintDocument named pd have been created on a Form. Make sure the Click event for the Button is associated with the printButton_Click method and the PrintPage event of the PrintDocument is associated with the pd_PrintPage method in the example. The printButton_Click method from the example calls the Print method raising the PrintPage event, and prints the .bmp file specified in the pd_PrintPage method. To run this example, change the path to the bitmap you want to print.

Use the System.Drawing, System.Drawing.Printing, and System.Windows.Forms namespaces for this example.

   ' Specifies what happens when the user clicks the Button.
   Private Sub printButton_Click(sender As Object, e As EventArgs) _
Handles printButton.Click
       Catch ex As Exception
           MessageBox.Show("An error occurred while printing", _
       End Try
   End Sub    

   ' Specifies what happens when the PrintPage event is raised.
   Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs) _
Handles pd.PrintPage

       ' Draw a picture.
       ev.Graphics.DrawImage(Image.FromFile("C:\My Folder\MyFile.bmp"), _

       ' Indicate that this is the last page to print.
       ev.HasMorePages = False
   End Sub

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft