PrinterSettings Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Specifies information about how a document is printed, including the printer that prints it, when printing from a Windows Forms application.
public ref class PrinterSettings : ICloneable
public class PrinterSettings : ICloneable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class PrinterSettings : ICloneable
[System.Serializable]
public class PrinterSettings : ICloneable
type PrinterSettings = class
interface ICloneable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type PrinterSettings = class
interface ICloneable
[<System.Serializable>]
type PrinterSettings = class
interface ICloneable
Public Class PrinterSettings
Implements ICloneable
- Inheritance
-
PrinterSettings
- Attributes
- Implements
The following code example prints a document on the specified printer. The example has three prerequisites:
A variable named
filePath
has been set to the path of the file to print.A method named
pd_PrintPage
, which handles the PrintPage event, has been defined.A variable named
printer
has been set to the printer's name.
Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.
public:
void Printing( String^ printer )
{
try
{
streamToPrint = gcnew StreamReader( filePath );
try
{
printFont = gcnew System::Drawing::Font( "Arial",10 );
PrintDocument^ pd = gcnew PrintDocument;
pd->PrintPage += gcnew PrintPageEventHandler(
this, &Form1::pd_PrintPage );
// Specify the printer to use.
pd->PrinterSettings->PrinterName = printer;
if ( pd->PrinterSettings->IsValid )
{
pd->Print();
}
else
{
MessageBox::Show( "Printer is invalid." );
}
}
finally
{
streamToPrint->Close();
}
}
catch ( Exception^ ex )
{
MessageBox::Show( ex->Message );
}
}
public void Printing(string printer) {
try {
streamToPrint = new StreamReader (filePath);
try {
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Specify the printer to use.
pd.PrinterSettings.PrinterName = printer;
if (pd.PrinterSettings.IsValid) {
pd.Print();
}
else {
MessageBox.Show("Printer is invalid.");
}
}
finally {
streamToPrint.Close();
}
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
Public Sub Printing(printer As String)
Try
streamToPrint = New StreamReader(filePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Specify the printer to use.
pd.PrinterSettings.PrinterName = printer
If pd.PrinterSettings.IsValid then
pd.Print()
Else
MessageBox.Show("Printer is invalid.")
End If
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Typically, you access a PrinterSettings through PrintDocument.PrinterSettings or PageSettings.PrinterSettings properties to modify printer settings. The most common printer setting is PrinterName, which specifies the printer to print to.
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.
Note
In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.
Printer |
Initializes a new instance of the PrinterSettings class. |
Can |
Gets a value indicating whether the printer supports double-sided printing. |
Collate |
Gets or sets a value indicating whether the printed document is collated. |
Copies |
Gets or sets the number of copies of the document to print. |
Default |
Gets the default page settings for this printer. |
Duplex |
Gets or sets the printer setting for double-sided printing. |
From |
Gets or sets the page number of the first page to print. |
Installed |
Gets the names of all printers installed on the computer. |
Is |
Gets a value indicating whether the PrinterName property designates the default printer, except when the user explicitly sets PrinterName. |
Is |
Gets a value indicating whether the printer is a plotter. |
Is |
Gets a value indicating whether the PrinterName property designates a valid printer. |
Landscape |
Gets the angle, in degrees, that the portrait orientation is rotated to produce the landscape orientation. |
Maximum |
Gets the maximum number of copies that the printer enables the user to print at a time. |
Maximum |
Gets or sets the maximum FromPage or ToPage that can be selected in a PrintDialog. |
Minimum |
Gets or sets the minimum FromPage or ToPage that can be selected in a PrintDialog. |
Paper |
Gets the paper sizes that are supported by this printer. |
Paper |
Gets the paper source trays that are available on the printer. |
Printer |
Gets or sets the name of the printer to use. |
Printer |
Gets all the resolutions that are supported by this printer. |
Print |
Gets or sets the file name, when printing to a file. |
Print |
Gets or sets the page numbers that the user has specified to be printed. |
Print |
Gets or sets a value indicating whether the printing output is sent to a file instead of a port. |
Supports |
Gets a value indicating whether this printer supports color printing. |
To |
Gets or sets the number of the last page to print. |
Clone() |
Creates a copy of this PrinterSettings. |
Create |
Returns a Graphics that contains printer information that is useful when creating a PrintDocument. |
Create |
Returns a Graphics that contains printer information, optionally specifying the origin at the margins. |
Create |
Creates a Graphics associated with the specified page settings and optionally specifying the origin at the margins. |
Create |
Returns a Graphics that contains printer information associated with the specified PageSettings. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Creates a handle to a |
Get |
Creates a handle to a |
Get |
Creates a handle to a |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Is |
Gets a value indicating whether the printer supports printing the specified image file. |
Is |
Returns a value indicating whether the printer supports printing the specified image format. |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
Set |
Copies the relevant information out of the given handle and into the PrinterSettings. |
Set |
Copies the relevant information out of the given handle and into the PrinterSettings. |
To |
Provides information about the PrinterSettings in string form. |
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: