PrintDocument.DefaultPageSettings Propriedade

Definição

Obtém ou define as definições de página que são usadas como padrão para todas as páginas a imprimir.

public:
 property System::Drawing::Printing::PageSettings ^ DefaultPageSettings { System::Drawing::Printing::PageSettings ^ get(); void set(System::Drawing::Printing::PageSettings ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PageSettings DefaultPageSettings { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.DefaultPageSettings : System.Drawing.Printing.PageSettings with get, set
Public Property DefaultPageSettings As PageSettings

Valor de Propriedade

A PageSettings que especifica as definições padrão da página do documento.

Atributos

Exemplos

O exemplo de código seguinte define a orientação da página de um documento para paisagem e imprime o documento. O exemplo faz três suposições: que uma variável nomeada filePath foi definida para o caminho do ficheiro a imprimir; que um método chamado pd_PrintPage, que gere o PrintPage evento, foi definido; e que uma variável nomeada printer foi definida para o nome da impressora.

Use os System.Drawingnamespaces , System.Drawing.Printing, e System.IO para este exemplo.

public:
   void Printing()
   {
      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 );
            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

Observações

Pode especificar várias definições de página por defeito através da DefaultPageSettings propriedade. Por exemplo, a PageSettings.Color propriedade especifica se a página imprime a cores, a PageSettings.Landscape propriedade indica orientação paisagem ou retrato, e a PageSettings.Margins propriedade especifica as margens da página.

Para especificar definições página a página, tratar o PrintPage evento ou QueryPageSettings e modificar o PageSettings argumento incluído no PrintPageEventArgs ou QueryPageSettingsEventArgs, respetivamente.

Note

Depois de iniciada a impressão, alterações nas definições de página através da DefaultPageSettings propriedade não afetam as páginas que estão a ser impressas.

Aplica-se a

Ver também