PageSetupDialog 类

允许用户更改与页面相关的打印设置,包括边距和纸张方向。无法继承此类。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public NotInheritable Class PageSetupDialog
    Inherits CommonDialog
用法
Dim instance As PageSetupDialog
public sealed class PageSetupDialog : CommonDialog
public ref class PageSetupDialog sealed : public CommonDialog
public final class PageSetupDialog extends CommonDialog
public final class PageSetupDialog extends CommonDialog

备注

PageSetupDialog 对话框对给定 DocumentPageSettingsPrinterSettings 信息进行修改。用户可启用该对话框的各个部分以控制打印和边距,控制纸张方向、大小和来源,还可以显示“帮助”和网络按钮。MinMargins 属性定义用户可选择的最小边距。

创建 PageSetupDialog 类的实例时,读/写属性将被设置为初始值。有关这些值的列表,请参见 PageSetupDialog 构造函数。

因为 PageSetupDialog 需要显示页面设置,所以需要在调用 ShowDialog 之前设置 DocumentPrinterSettingsPageSettings 属性;否则将会发生异常。

示例

下面的代码示例使用 PageSettingsPrinterSettingsShowNetwork 属性阐释了 PageSetupDialog。若要运行此示例,请将它放到一个包含一个 Button(名为 Button1)、一个 ListBox(名为 ListBox1)和一个 PageSetupDialog(名为 PageSetupDialog1)的窗体中。确保该按钮的 Click 事件与此示例中的事件处理方法相连接。

'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
//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.
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.set_PageSettings(
        new System.Drawing.Printing.PageSettings());
    // Initialize dialog's PrinterSettings property to hold user
    // set printer settings.
    pageSetupDialog1.set_PrinterSettings(
        new System.Drawing.Printing.PrinterSettings());
    //Do not show the network in the printer dialog.
    pageSetupDialog1.set_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.Equals(get_DialogResult().OK)) {
        Object results[] = new Object[] {
            pageSetupDialog1.get_PageSettings().get_Margins(),
            pageSetupDialog1.get_PageSettings().get_PaperSize(),
            ((System.Boolean)pageSetupDialog1.get_PageSettings().
            get_Landscape()),
            pageSetupDialog1.get_PrinterSettings().get_PrinterName(),
            pageSetupDialog1.get_PrinterSettings().get_PrintRange()};
        listBox1.get_Items().AddRange(results);
    }
} //button1_Click

继承层次结构

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.CommonDialog
        System.Windows.Forms.PageSetupDialog

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

PageSetupDialog 成员
System.Windows.Forms 命名空间
CommonDialog 类
Margins
PageSettings
PrintDocument
PrinterSettings