Defines a reusable object that sends output to a printer, when printing from a Windows Forms application.
Assembly: System.Drawing (in System.Drawing.dll)
Typically, you create an instance of the 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.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.