更新:2007 年 11 月
PageSetupDialog 为用户提供文档的布局、页面大小以及其他页面布局选择。
需要指定 PrintDocument 类的一个实例,该类是要打印的文档。此外,用户必须通过本地安装或网络安装的方式,在自己的计算机上安装打印机,因为这会影响 PageSetupDialog 组件确定对用户显示哪些页面格式设置选项。
使用 PageSetupDialog 组件的一个重要方面是该组件如何与 PageSettings 类进行交互。PageSettings 类用于指定修改页面打印方式的设置,例如页面方向、页面大小以及页边距。这些设置中的每一个都表示为 PageSettings 类的一个属性。PageSetupDialog 类修改与文档相关联(并表示为 DefaultPageSettings 属性)的 PageSettings 类的给定实例的属性值。
使用 PageSetupDialog 组件设置页面属性
- 使用 ShowDialog 方法显示对话框,同时指定要使用的 PrintDocument。 - 在下面的示例中,Button 控件的 Click 事件处理程序打开了 PageSetupDialog 组件的一个实例。在 Document 属性中指定了一个现有的文档,并将其 PageSettings.Color 属性设为 false。 - 本示例假设窗体上有一个 Button 控件、一个名为 myDocument 的 PrintDocument 组件以及一个 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 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.set_Document(myDocument); // Sets the print document's color setting to false, // so that the page will not be printed in color. pageSetupDialog1.get_Document().get_DefaultPageSettings().set_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 J# 和 Visual C++)在窗体的构造函数中放置以下代码,以注册事件处理程序。 - this.button1.Click += new System.EventHandler(this.button1_Click);- this.button1.add_Click(new System.EventHandler(this.button1_Click));- this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);