クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
以前のバージョン
.NET Framework SDK 2.0
System.Drawing.Printing
PrinterSettings クラス

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2005/.NET Framework 2.0

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
PrinterSettings クラス

ドキュメントの印刷方法に関する情報 (印刷に使用するプリンタなど) を指定します。

名前空間: System.Drawing.Printing
アセンブリ: System.Drawing (system.drawing.dll 内)

Visual Basic (宣言)
<SerializableAttribute> _
Public Class PrinterSettings
    Implements ICloneable
Visual Basic (使用法)
Dim instance As PrinterSettings
C#
[SerializableAttribute] 
public class PrinterSettings : ICloneable
C++
[SerializableAttribute] 
public ref class PrinterSettings : ICloneable
J#
/** @attribute SerializableAttribute() */ 
public class PrinterSettings implements ICloneable
JScript
SerializableAttribute 
public class PrinterSettings implements ICloneable

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

印刷の詳細については、System.Drawing.Printing 名前空間の概要のトピックを参照してください。

指定したプリンタ上でドキュメントを印刷するコード例を次に示します。この例には、次の 3 つの必要条件があります。

  • 変数 filePath が印刷するファイルのパスに設定されていること。

  • PrintPage イベントを処理する pd_PrintPage メソッドが定義されていること。

  • 変数 printer がプリンタ名に設定されていること。

この例では、System.DrawingSystem.Drawing.Printing、および System.IO の各名前空間を使用します。

Visual Basic
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
   
C#
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);
  }
}

C++
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 );
      }
   }
J#
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.Object
  System.Drawing.Printing.PrinterSettings
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

.NET Framework

サポート対象 : 2.0、1.1、1.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker