如何:使用 PageSetupDialog 元件決定頁面屬性
PageSetupDialog 元件會向文件使用者呈現配置、紙張大小和其他頁面配置選項。
您需要指定 PrintDocument 類別執行個體,這是要列印文件。 此外,使用者必須在其電腦上安裝印表機 (本機或透過網路),因為這有一部分是 PageSetupDialog 元件如何決定呈現給使用者的頁面格式選項。
使用 PageSetupDialog 元件的重要層面是如何與 PageSettings 類別互動。 PageSettings 類別是用來指定可修改頁面列印方式的設定,例如紙張列印方向,頁面大小和邊界。 所有這些設定都是呈現為 PageSettings 類別的屬性。 PageSetupDialog 類別會針對與文件相關聯 (並呈現為 PageSettings 屬性) 的指定 DefaultPageSettings 類別執行個體來修改這些屬性值。
使用 PageSetupDialog 元件決定頁面屬性
使用 ShowDialog 方法顯示對話方塊,並指定要使用的 PrintDocument 。
在下列範例中, Button 控制項的 Click 事件處理常式會開啟 PageSetupDialog 元件執行個體。 現有的文件指定於 Document 屬性中,而且其 PageSettings.Color 屬性設定為
false
。此範例假設您的表單具有 Button 控制項、名為 PrintDocument 的
myDocument
元件,以及 PageSetupDialog 元件。Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ' The print document 'myDocument' used below ' is merely for an example. 'You will have to specify your own print document. PageSetupDialog1.Document = myDocument ' Sets the print document's color setting to false, ' so that the page will not be printed in color. PageSetupDialog1.Document.DefaultPageSettings.Color = False PageSetupDialog1.ShowDialog() End Sub
private void button1_Click(object sender, System.EventArgs e) { // The print document 'myDocument' used below // is merely for an example. // You will have to specify your own print document. pageSetupDialog1.Document = myDocument; // Sets the print document's color setting to false, // so that the page will not be printed in color. pageSetupDialog1.Document.DefaultPageSettings.Color = false; pageSetupDialog1.ShowDialog(); }
private: System::Void button1_Click(System::Object ^ sender, System::EventArgs ^ e) { // The print document 'myDocument' used below // is merely for an example. // You will have to specify your own print document. pageSetupDialog1->Document = myDocument; // Sets the print document's color setting to false, // so that the page will not be printed in color. pageSetupDialog1->Document->DefaultPageSettings->Color = false; pageSetupDialog1->ShowDialog(); }
(Visual C# 和 Visual C++) 請將下列程式碼置於表單的建構函式中,以登錄事件處理常式。
this.button1.Click += new System.EventHandler(this.button1_Click);
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);