PrinterSettings::PrinterName Property
Gets or sets the name of the printer to use.
Assembly: System.Drawing (in System.Drawing.dll)
After setting the printer name, call IsValid to determine if the printer name is recognized as a valid printer on the system.
You can also use the InstalledPrinters property to get a list of printers installed on the system.
The following code example specifies the target printer by setting the PrinterName property, and if the IsValid is true, prints the 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 ); } }
for printing and access to all printers on the network. Associated enumeration: PrintingPermissionLevel::AllPrinting
Available since 1.1