PrintDocument.DefaultPageSettings 屬性

定義

取得或設定頁面設定,其會使用為所有要列印頁面的預設設定。

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

屬性值

指定文件預設頁面設定的 PageSettings

屬性

範例

下列程式代碼範例會將文件的頁面方向設定為橫向,並列印檔。 此範例會假設名為 filePath 的變數已設定為要列印的檔案路徑;名為 pd_PrintPage的方法會處理 PrintPage 事件、已定義;且名為 printer 的變數已設定為印表機的名稱。

針對此範例, System.Drawing請使用、 System.Drawing.PrintingSystem.IO 命名空間。

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

備註

您可以透過 DefaultPageSettings 屬性指定數個預設頁面設定。 例如, PageSettings.Color 屬性會指定頁面是否以色彩列印、 PageSettings.Landscape 屬性指定橫向或直向,而 PageSettings.Margins 屬性會指定頁面的邊界。

若要逐頁指定設定,請分別處理 PrintPageQueryPageSettings 事件,並修改 PageSettingsQueryPageSettingsEventArgs中包含的PrintPageEventArgs自變數。

注意

列印開始之後,透過 DefaultPageSettings 屬性變更頁面設定不會影響列印的頁面。

適用於

另請參閱