PageSettings.Landscape Propiedad

Definición

Obtiene o establece un valor que indica si debe imprimirse la página con orientación horizontal o vertical.

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

Valor de propiedad

truesi la página debe imprimirse en horizontal; en caso contrario, false. El valor predeterminado lo determina la impresora.

Excepciones

La impresora que se menciona en la propiedad PrinterName no existe.

Ejemplos

En el ejemplo de código siguiente se establece la orientación de página predeterminada de un documento en horizontal a través de la PrintDocument.DefaultPageSettings propiedad e imprime el documento. El ejemplo tiene tres requisitos previos:

  • Se ha establecido una variable denominada filePath en la ruta de acceso del archivo que se va a imprimir.

  • Se ha definido un método denominado pd_PrintPage, que controla el PrintPage evento .

  • Se ha establecido una variable denominada printer en el nombre de la impresora.

Use los System.Drawingespacios de nombres , System.Drawing.Printingy System.IO para este ejemplo.

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

Comentarios

Puede usar la PrinterSettings.LandscapeAngle propiedad para determinar el ángulo, en grados, que la orientación vertical se gira para generar la orientación horizontal.

Se aplica a

Consulte también