Specifies information about how a document is printed, including the printer that prints it, when printing from a Windows Forms application.
Namespace:
System.Drawing.Printing
Assembly:
System.Drawing (in System.Drawing.dll)
Visual Basic (Declaration)
<SerializableAttribute> _
Public Class PrinterSettings _
Implements ICloneable
Dim instance As PrinterSettings
[SerializableAttribute]
public class PrinterSettings : ICloneable
[SerializableAttribute]
public ref class PrinterSettings : ICloneable
public class PrinterSettings implements ICloneable
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.
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 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
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:
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 );
}
}
System..::.Object
System.Drawing.Printing..::.PrinterSettings
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference