PrintDocument Class
![]() |
---|
The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience. |
Defines a reusable object that sends output to a printer, when printing from a Windows Forms application.
Assembly: System.Drawing (in System.Drawing.dll)
System.MarshalByRefObject
System.ComponentModel.Component
System.Drawing.Printing.PrintDocument
Name | Description | |
---|---|---|
![]() | PrintDocument() | Initializes a new instance of the PrintDocument class. |
Name | Description | |
---|---|---|
![]() | CanRaiseEvents | Gets a value indicating whether the component can raise an event.(Inherited from Component.) |
![]() | Container | Gets the IContainer that contains the Component.(Inherited from Component.) |
![]() | DefaultPageSettings | Gets or sets page settings that are used as defaults for all pages to be printed. |
![]() | DesignMode | |
![]() | DocumentName | Gets or sets the document name to display (for example, in a print status dialog box or printer queue) while printing the document. |
![]() | Events | |
![]() | OriginAtMargins | Gets or sets a value indicating whether the position of a graphics object associated with a page is located just inside the user-specified margins or at the top-left corner of the printable area of the page. |
![]() | PrintController | Gets or sets the print controller that guides the printing process. |
![]() | PrinterSettings | Gets or sets the printer that prints the document. |
![]() | Site |
Name | Description | |
---|---|---|
![]() | CreateObjRef(Type) | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.) |
![]() | Dispose() | |
![]() | Dispose(Boolean) | |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetLifetimeService() | Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | GetService(Type) | |
![]() | GetType() | |
![]() | InitializeLifetimeService() | Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone() | |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.) |
![]() | OnBeginPrint(PrintEventArgs) | Raises the BeginPrint event. It is called after the Print method is called and before the first page of the document prints. |
![]() | OnEndPrint(PrintEventArgs) | Raises the EndPrint event. It is called when the last page of the document has printed. |
![]() | OnPrintPage(PrintPageEventArgs) | Raises the PrintPage event. It is called before a page prints. |
![]() | OnQueryPageSettings(QueryPageSettingsEventArgs) | Raises the QueryPageSettings event. It is called immediately before each PrintPage event. |
![]() | Print() | Starts the document's printing process. |
![]() | ToString() | This API supports the product infrastructure and is not intended to be used directly from your code. Provides information about the print document, in string form.(Overrides Component.ToString().) |
Name | Description | |
---|---|---|
![]() | BeginPrint | Occurs when the Print method is called and before the first page of the document prints. |
![]() | Disposed | |
![]() | EndPrint | Occurs when the last page of the document has printed. |
![]() | PrintPage | Occurs when the output to print for the current page is needed. |
![]() | QueryPageSettings | Occurs immediately before each PrintPage event. |
Typically, you create an instance of the PrintDocument class, set properties such as the DocumentNameand PrinterSettings, and call the Print method to start the printing process. Handle the PrintPage event where you specify the output to print, by using the GraphicsGraphics property of the PrintPageEventArgs.
For more information about printing from a Windows Form application, see the Windows Forms Print Support. If you wish to print from a Windows Presentation Foundation application, see the System.Printing namespace.
The following code example prints the file named C:\My Documents\MyFile.txt on the default printer. To run the example, create a new Windows Forms project and paste the example code into the form, replacing the file contents. For C#, you will need to delete the Form1.Designer.cs file. Also, change the path to the file you want to print.
![]() |
---|
The example requires that each line fits within the page width. |
Use the System.ComponentModel, System.Windows.Forms, System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.
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.