PageSettings.Landscape プロパティ

定義

ページの印刷時に用紙を横向きにするか縦向きにするかを示す値を取得または設定します。

public:
 property bool Landscape { bool get(); void set(bool value); };
public bool Landscape { get; set; }
member this.Landscape : bool with get, set
Public Property Landscape As Boolean

プロパティ値

ページを横向きで印刷する場合は true。それ以外の場合は false。 既定値はプリンターによって決定されます。

例外

PrinterName プロパティで指定されたプリンターが存在しません。

次のコード例では、 プロパティを使用してドキュメントの既定のページの向きを PrintDocument.DefaultPageSettings 横向きに設定し、ドキュメントを印刷します。 この例には、次の 3 つの前提条件があります。

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

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

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

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

public:
   void Printing()
   {
      try
      {
         streamToPrint = gcnew StreamReader( filePath );
         try
         {
            printFont = gcnew Font( "Arial",10 );
            PrintDocument^ pd = gcnew PrintDocument;
            pd->PrintPage += gcnew PrintPageEventHandler(
               this, &Sample::pd_PrintPage );
            pd->PrinterSettings->PrinterName = printer;
            // Set the page orientation to landscape.
            pd->DefaultPageSettings->Landscape = true;
            pd->Print();
         }
         finally
         {
            streamToPrint->Close();
         }
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( ex->Message );
      }
   }
public void Printing() {
   try {
     streamToPrint = new StreamReader (filePath);
     try {
       printFont = new Font("Arial", 10);
       PrintDocument pd = new PrintDocument(); 
       pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
       pd.PrinterSettings.PrinterName = printer;
       // Set the page orientation to landscape.
       pd.DefaultPageSettings.Landscape = true;
       pd.Print();
     } 
     finally {
       streamToPrint.Close() ;
     }
   } 
   catch(Exception ex) { 
     MessageBox.Show(ex.Message);
   }
 }
Public Sub Printing()
    Try
        streamToPrint = New StreamReader(filePath)
        Try
            printFont = New Font("Arial", 10)
            Dim pd As New PrintDocument()
            AddHandler pd.PrintPage, AddressOf pd_PrintPage
            pd.PrinterSettings.PrinterName = printer
            ' Set the page orientation to landscape.
            pd.DefaultPageSettings.Landscape = True
            pd.Print()
        Finally
            streamToPrint.Close()
        End Try
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

注釈

プロパティを PrinterSettings.LandscapeAngle 使用すると、縦向きが回転して横向きを生成する角度を度単位で決定できます。

適用対象

こちらもご覧ください