PageSetupDialog 類別

定義

讓使用者可以變更頁面相關的列印設定,包括邊界和紙張方向。 此類別無法獲得繼承。

public ref class PageSetupDialog sealed : System::Windows::Forms::CommonDialog
public sealed class PageSetupDialog : System.Windows.Forms.CommonDialog
type PageSetupDialog = class
    inherit CommonDialog
Public NotInheritable Class PageSetupDialog
Inherits CommonDialog
繼承

範例

下列程式碼範例示範 PageSetupDialog 如何使用 PageSettingsPrinterSettingsShowNetwork 屬性。 若要執行此範例,請將它放在包含 Button 具名 、 ListBox 具名 Button1ListBox1 和具名 PageSetupDialog1 的表單中 PageSetupDialog 。 請確定按鈕的 Click 事件已連線到此範例中的事件處理方法。

//This method displays a PageSetupDialog object. If the
// user clicks OK in the dialog, selected results of
// the dialog are displayed in ListBox1.
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   
   // Initialize the dialog's PrinterSettings property to hold user
   // defined printer settings.
   PageSetupDialog1->PageSettings = gcnew System::Drawing::Printing::PageSettings;
   
   // Initialize dialog's PrinterSettings property to hold user
   // set printer settings.
   PageSetupDialog1->PrinterSettings = gcnew System::Drawing::Printing::PrinterSettings;
   
   //Do not show the network in the printer dialog.
   PageSetupDialog1->ShowNetwork = false;
   
   //Show the dialog storing the result.
   System::Windows::Forms::DialogResult result = PageSetupDialog1->ShowDialog();
   
   // If the result is OK, display selected settings in
   // ListBox1. These values can be used when printing the
   // document.
   if ( result == ::DialogResult::OK )
   {
      array<Object^>^results = {PageSetupDialog1->PageSettings->Margins,PageSetupDialog1->PageSettings->PaperSize,PageSetupDialog1->PageSettings->Landscape,PageSetupDialog1->PrinterSettings->PrinterName,PageSetupDialog1->PrinterSettings->PrintRange};
      ListBox1->Items->AddRange( results );
   }
   
}

//This method displays a PageSetupDialog object. If the
// user clicks OK in the dialog, selected results of
// the dialog are displayed in ListBox1.
private void Button1_Click(System.Object sender, System.EventArgs e)
{

    // Initialize the dialog's PrinterSettings property to hold user
    // defined printer settings.
    PageSetupDialog1.PageSettings =
        new System.Drawing.Printing.PageSettings();

    // Initialize dialog's PrinterSettings property to hold user
    // set printer settings.
    PageSetupDialog1.PrinterSettings =
        new System.Drawing.Printing.PrinterSettings();

    //Do not show the network in the printer dialog.
    PageSetupDialog1.ShowNetwork = false;

    //Show the dialog storing the result.
    DialogResult result = PageSetupDialog1.ShowDialog();

    // If the result is OK, display selected settings in
    // ListBox1. These values can be used when printing the
    // document.
    if (result == DialogResult.OK)
    {
        object[] results = new object[]{ 
            PageSetupDialog1.PageSettings.Margins, 
            PageSetupDialog1.PageSettings.PaperSize, 
            PageSetupDialog1.PageSettings.Landscape, 
            PageSetupDialog1.PrinterSettings.PrinterName, 
            PageSetupDialog1.PrinterSettings.PrintRange};
        ListBox1.Items.AddRange(results);
    }
}

'This method displays a PageSetupDialog object. If the
' user clicks OK in the dialog, selected results of
' the dialog are displayed in ListBox1.
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Initialize the dialog's PrinterSettings property to hold user
    ' defined printer settings.
    PageSetupDialog1.PageSettings = _
        New System.Drawing.Printing.PageSettings

    ' Initialize dialog's PrinterSettings property to hold user
    ' set printer settings.
    PageSetupDialog1.PrinterSettings = _
        New System.Drawing.Printing.PrinterSettings

    'Do not show the network in the printer dialog.
    PageSetupDialog1.ShowNetwork = False

    'Show the dialog storing the result.
    Dim result As DialogResult = PageSetupDialog1.ShowDialog()

    ' If the result is OK, display selected settings in
    ' ListBox1. These values can be used when printing the
    ' document.
    If (result = DialogResult.OK) Then
        Dim results() As Object = New Object() _
            {PageSetupDialog1.PageSettings.Margins, _
             PageSetupDialog1.PageSettings.PaperSize, _
             PageSetupDialog1.PageSettings.Landscape, _
             PageSetupDialog1.PrinterSettings.PrinterName, _
             PageSetupDialog1.PrinterSettings.PrintRange}
        ListBox1.Items.AddRange(results)
    End If

End Sub

備註

PageSetupDialog對話方塊會修改指定 DocumentPageSettings 的 和 PrinterSettings 資訊。 使用者可以啟用對話方塊的區段來操作列印和邊界;紙張方向、大小和來源;和 以顯示 [說明] 和 [網路] 按鈕。 屬性 MinMargins 會定義使用者可以選取的最小邊界。

當您建立 類別的 PageSetupDialog 實例時,讀取/寫入屬性會設定為初始值。 如需這些值的清單,請參閱建 PageSetupDialog 構函式。

因為 需要 PageSetupDialog 頁面設定才能顯示,所以您必須在呼叫 ShowDialog 之前設定 DocumentPrinterSettingsPageSettings 屬性,否則會發生例外狀況。

建構函式

PageSetupDialog()

初始化 PageSetupDialog 類別的新執行個體。

屬性

AllowMargins

取得或設定值,指出是否啟用對話方塊邊界區段。

AllowOrientation

取得或設定值,指出是否啟用對話方塊的方向區段 (橫向和縱向)。

AllowPaper

取得或設定值,指出是否啟用對話方塊的紙張區段 (紙張大小和紙張來源)。

AllowPrinter

取得或設定值,指出是否啟用 [印表機] 按鈕。

CanRaiseEvents

取得值,指出元件是否能引發事件。

(繼承來源 Component)
Container

取得包含 IContainerComponent

(繼承來源 Component)
DesignMode

取得值,指出 Component 目前是否處於設計模式。

(繼承來源 Component)
Document

取得或設定數值,表示 PrintDocument 從何處取得版面設定。

EnableMetric

取得或設定值,以表示當以公釐為單位顯示時,邊界設定是否自動在公釐與百分之一英吋間轉換。

Events

取得附加在這個 Component 上的事件處理常式清單。

(繼承來源 Component)
MinMargins

取得或設定數值,表示允許使用者選取的最小邊界,以百分之一英吋為單位。

PageSettings

取得或設定數值,表示要修改的頁面設定。

PrinterSettings

取得或設定當使用者按一下對話方塊中的 [印表機] 按鈕時,要修改的印表機設定。

ShowHelp

取得或設定值,指出 [說明] 按鈕是否為可見。

ShowNetwork

取得或設定值,指出 [網路] 按鈕是否為可見。

Site

取得或設定 ComponentISite

(繼承來源 Component)
Tag

取得或設定包含控制項相關資料的物件。

(繼承來源 CommonDialog)

方法

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。

(繼承來源 Component)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

定義為了將特定功能加入通用對話方塊中而覆寫的通用對話方塊攔截程序。

(繼承來源 CommonDialog)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
OnHelpRequest(EventArgs)

引發 HelpRequest 事件。

(繼承來源 CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

定義為了將特定功能加入通用對話方塊中而覆寫的主控視窗 (Owner Window) 程序。

(繼承來源 CommonDialog)
Reset()

將所有選項重設為預設值。

RunDialog(IntPtr)

在衍生類別中覆寫時,指定通用對話方塊。

(繼承來源 CommonDialog)
ShowDialog()

以預設的擁有人來執行通用對話方塊。

(繼承來源 CommonDialog)
ShowDialog(IWin32Window)

以指定的擁有人來執行通用對話方塊。

(繼承來源 CommonDialog)
ToString()

傳回任何包含 Component 名稱的 String。 不應覆寫此方法。

(繼承來源 Component)

事件

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。

(繼承來源 Component)
HelpRequest

發生於使用者按一下通用對話方塊上的 [說明] 按鈕時。

(繼承來源 CommonDialog)

適用於

另請參閱