PrinterSettings クラス

定義

Windows フォーム アプリケーションから印刷する場合のドキュメントの印刷方法に関する情報 (印刷に使用するプリンターなど) を指定します。

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
継承
PrinterSettings
属性
実装

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

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

  • イベントを処理する という名前 pd_PrintPagePrintPage メソッドが定義されています。

  • という名前 printer の変数がプリンターの名前に設定されています。

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

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

注釈

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

Windows フォームを使用した印刷の詳細については、名前空間の概要に関するページをSystem.Drawing.Printing参照してください。 Windows Presentation Foundation アプリケーションから印刷する場合は、 名前空間をSystem.Printing参照してください。

Note

.NET 6 以降のバージョンでは、この種類を含む System.Drawing.Common パッケージは Windows オペレーティング システムでのみサポートされています。 クロスプラットフォーム アプリでこの型を使用すると、コンパイル時の警告と実行時例外が発生します。 詳細については、「 Windows でのみサポートされる System.Drawing.Common」を参照してください。

コンストラクター

PrinterSettings()

PrinterSettings クラスの新しいインスタンスを初期化します。

プロパティ

CanDuplex

プリンターが両面印刷をサポートしているかどうかを示す値を取得します。

Collate

ドキュメントを部単位で印刷するかどうかを示す値を取得または設定します。

Copies

印刷するドキュメントの部数を取得または設定します。

DefaultPageSettings

プリンターの既定のページ設定を取得します。

Duplex

両面印刷用のプリンター設定を取得または設定します。

FromPage

印刷開始ページの番号を取得または設定します。

InstalledPrinters

コンピューターにインストールされているすべてのプリンターの名前を取得します。

IsDefaultPrinter

ユーザーが明示的に PrinterName を設定した場合を除き、PrinterName プロパティが、通常使うプリンターに指定されているかどうかを示す値を取得します。

IsPlotter

プリンターがプロッターかどうかを示す値を取得します。

IsValid

PrinterName プロパティが有効なプリンターに指定されているかどうかを示す値を取得します。

LandscapeAngle

縦向きの用紙を回転して横向きにする場合の角度 (°) を取得します。

MaximumCopies

プリンターで一度に印刷できる最大部数を取得します。

MaximumPage

FromPage で選択できる ToPage または PrintDialog の最大値を取得または設定します。

MinimumPage

FromPage で選択できる ToPage または PrintDialog の最小値を取得または設定します。

PaperSizes

プリンターでサポートされている用紙サイズを取得します。

PaperSources

プリンターで使用できる用紙トレイを取得します。

PrinterName

使用するプリンターの名前を取得または設定します。

PrinterResolutions

プリンターでサポートされている解像度をすべて取得します。

PrintFileName

ファイルに出力する際にファイル名を取得または設定します。

PrintRange

ユーザーが指定した印刷ページの番号を取得または設定します。

PrintToFile

ポートではなく、ファイルに印刷出力を送信するかどうかを示す値を取得または設定します。

SupportsColor

プリンターがカラー印刷をサポートしているかどうかを示す値を取得します。

ToPage

印刷終了ページの番号を取得または設定します。

メソッド

Clone()

この PrinterSettings のコピーを作成します。

CreateMeasurementGraphics()

Graphics の作成時に役立つプリンター情報を格納する PrintDocument を返します。

CreateMeasurementGraphics(Boolean)

プリンター情報を格納し、オプションで余白の原点を指定する Graphics を返します。

CreateMeasurementGraphics(PageSettings)

指定した Graphics に関連付けられたプリンター情報を格納する PageSettings を返します。

CreateMeasurementGraphics(PageSettings, Boolean)

指定したページ設定に関連付けられ、オプションで余白の原点を指定する Graphics を作成します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetHdevmode()

プリンター設定に対応する DEVMODE 構造体を識別するハンドルを作成します。

GetHdevmode(PageSettings)

プリンター設定や、pageSettings パラメーターで指定されたページ設定に対応する DEVMODE 構造体を識別するハンドルを作成します。

GetHdevnames()

プリンター設定に対応する DEVNAMES 構造体を識別するハンドルを作成します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDirectPrintingSupported(Image)

指定したイメージ ファイルの印刷をプリンターがサポートしているかどうかを示す値を取得します。

IsDirectPrintingSupported(ImageFormat)

指定したイメージ形式の印刷をプリンターがサポートしているかどうかを示す値を返します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
SetHdevmode(IntPtr)

特定のハンドルから PrinterSettings に関連情報をコピーします。

SetHdevnames(IntPtr)

特定のハンドルから PrinterSettings に関連情報をコピーします。

ToString()

PrinterSettings に関する情報を文字列形式で提供します。

適用対象

こちらもご覧ください