PrintPageEventArgs Class
Provides data for the PrintPage event.
Assembly: System.Drawing (in System.Drawing.dll)
The PrintPageEventArgs type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Cancel | Gets or sets a value indicating whether the print job should be canceled. |
![]() | Graphics | Gets the Graphics used to paint the page. |
![]() | HasMorePages | Gets or sets a value indicating whether an additional page should be printed. |
![]() | MarginBounds | Gets the rectangular area that represents the portion of the page inside the margins. |
![]() | PageBounds | Gets the rectangular area that represents the total area of the page. |
![]() | PageSettings | Gets the page settings for the current page. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | 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.
private: // Specifies what happens when the user clicks the Button. void printButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ ) { try { pd->Print(); } catch ( Exception^ ex ) { MessageBox::Show( "An error occurred while printing", ex->ToString() ); } } // Specifies what happens when the PrintPage event is raised. void pd_PrintPage( Object^ /*sender*/, PrintPageEventArgs^ ev ) { // Draw a picture. ev->Graphics->DrawImage( Image::FromFile( "C:\\My Folder\\MyFile.bmp" ), ev->Graphics->VisibleClipBounds ); // Indicate that this is the last page to print. ev->HasMorePages = false; }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
