PrinterSettings クラス

定義

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

public ref class PrinterSettings : ICloneable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class PrinterSettings : ICloneable
[System.Serializable]
public class PrinterSettings : 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_PrintPage イベントを処理する PrintPage という名前のメソッドが定義されています。

  • 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

注釈

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

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

Note

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

コンストラクター

名前 説明
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()

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

CreateMeasurementGraphics(Boolean)

プリンター情報を含む Graphics を返します。必要に応じて、余白の原点を指定します。

CreateMeasurementGraphics(PageSettings, Boolean)

指定したページ設定に関連付けられた Graphics を作成し、必要に応じて余白に原点を指定します。

CreateMeasurementGraphics(PageSettings)

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

Equals(Object)

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

(継承元 Object)
GetHashCode()

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

(継承元 Object)
GetHdevmode()

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

GetHdevmode(PageSettings)

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

GetHdevnames()

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

GetType()

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

(継承元 Object)
IsDirectPrintingSupported(Image)

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

IsDirectPrintingSupported(ImageFormat)

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

MemberwiseClone()

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

(継承元 Object)
SetHdevmode(IntPtr)

指定されたハンドルから PrinterSettingsに関連情報をコピーします。

SetHdevnames(IntPtr)

指定されたハンドルから PrinterSettingsに関連情報をコピーします。

ToString()

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

適用対象

こちらもご覧ください