PrinterSettings クラス
アセンブリ: System.Drawing (system.drawing.dll 内)


通常、PrintDocument.PrinterSettings プロパティまたは PageSettings.PrinterSettings プロパティを使用して PrinterSettings にアクセスし、プリンタ設定を変更します。最も一般的なプリンタ設定は、印刷するプリンタを指定する PrinterName です。

指定したプリンタ上でドキュメントを印刷するコード例を次に示します。この例には、次の 3 つの必要条件があります。
この例では、System.Drawing、System.Drawing.Printing、および System.IO の各名前空間を使用します。
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 ); } }
public void Printing(String printer) { try { streamToPrint = new StreamReader(filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.add_PrintPage(new PrintPageEventHandler(pd_PrintPage)); // Specify the printer to use. pd.get_PrinterSettings().set_PrinterName(printer); if (pd.get_PrinterSettings().get_IsValid()) { pd.Print(); } else { MessageBox.Show("Printer is invalid."); } } finally { streamToPrint.Close(); } } catch (System.Exception ex) { MessageBox.Show(ex.get_Message()); } } //Printing

System.Drawing.Printing.PrinterSettings


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- PrinterSettings クラスのページへのリンク