PageSetupDialog 类

定义

允许用户更改与页面相关的打印设置,包括边距和纸张方向。Enables users to change page-related print settings, including margins and paper orientation. 此类不能被继承。This class cannot be inherited.

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 PageSettings使用、 PrinterSettingsShowNetwork属性。The following code example demonstrates the PageSetupDialog using the PageSettings, PrinterSettings, and ShowNetwork properties. 若要运行此示例, 请将其放在包含ButtonButton1 ListBox为、名ListBox1为的的PageSetupDialogPageSetupDialog1体和名为的的窗体中。To run this example, place it in a form containing a Button named Button1, a ListBox named ListBox1, and a PageSetupDialog named PageSetupDialog1. 确保该按钮的 click 事件已连接到此示例中的事件处理方法。Ensure the button's click event is connected to the event-handling method in this example.

//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 PrinterSettings 对话框PageSettings修改给定Document的和信息。The PageSetupDialog dialog box modifies the PageSettings and PrinterSettings information for a given Document. 用户可以启用对话框部分来处理打印和边距;纸张方向、大小和源;并显示 "帮助" 和 "网络" 按钮。The user can enable sections of the dialog box to manipulate printing and margins; paper orientation, size, and source; and to show Help and network buttons. MinMargins属性定义用户可选择的最小边距。The MinMargins property defines the minimum margins a user can select.

创建PageSetupDialog类的实例时, 读/写属性将设置为初始值。When you create an instance of the PageSetupDialog class, the read/write properties are set to initial values. 有关这些值的列表, 请参见PageSetupDialog构造函数。For a list of these values, see the PageSetupDialog constructor.

ShowDialog PageSettings PrinterSettings Document由于需要显示页设置, 因此需要在调用之前设置、或属性; 否则, 将发生异常。 PageSetupDialogBecause a PageSetupDialog needs page settings to display, you need to set the Document, PrinterSettings, or PageSettings property before calling ShowDialog; otherwise, an exception will occur.

构造函数

PageSetupDialog()

初始化 PageSetupDialog 类的新实例。Initializes a new instance of the PageSetupDialog class.

属性

AllowMargins

获取或设置一个值,该值指示是否启用对话框的边距部分。Gets or sets a value indicating whether the margins section of the dialog box is enabled.

AllowOrientation

获取或设置一个值,该值指示是否启用对话框的方向部分(横向对纵向)。Gets or sets a value indicating whether the orientation section of the dialog box (landscape versus portrait) is enabled.

AllowPaper

获取或设置一个值,该值指示是否启用对话框的纸张部分(纸张大小和纸张来源)。Gets or sets a value indicating whether the paper section of the dialog box (paper size and paper source) is enabled.

AllowPrinter

获取或设置一个值,该值指示是否启用“打印机”按钮。Gets or sets a value indicating whether the Printer button is enabled.

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Document

获取或设置一个值,指示从中获取页面设置的 PrintDocumentGets or sets a value indicating the PrintDocument to get page settings from.

EnableMetric

获取或设置一个值,该值指示以毫米显示时,边距设置是否应在百分之一英寸与毫米之间自动转换。Gets or sets a value indicating whether the margin settings, when displayed in millimeters, should be automatically converted to and from hundredths of an inch.

Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
MinMargins

获取或设置一个值,该值指示允许用户选择的最小边距(以百分之一英寸为单位)。Gets or sets a value indicating the minimum margins, in hundredths of an inch, the user is allowed to select.

PageSettings

获取或设置一个值,该值指示要修改的页设置。Gets or sets a value indicating the page settings to modify.

PrinterSettings

获取或设置用户单击对话框中“打印机”按钮时修改的打印机设置。Gets or sets the printer settings that are modified when the user clicks the Printer button in the dialog.

ShowHelp

获取或设置一个值,该值指示“帮助”按钮是否可见。Gets or sets a value indicating whether the Help button is visible.

ShowNetwork

获取或设置一个值,该值指示“网络”按钮是否可见。Gets or sets a value indicating whether the Network button is visible.

Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(继承自 Component)
Tag

获取或设置一个对象,该对象包含控件的数据。Gets or sets an object that contains data about the control.

(继承自 CommonDialog)

方法

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

定义要重写的通用对话框挂钩过程,以便向通用对话框添加特定功能。Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.

(继承自 CommonDialog)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
OnHelpRequest(EventArgs)

引发 HelpRequest 事件。Raises the HelpRequest event.

(继承自 CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

定义要重写的所有者窗口过程,以便向通用对话框添加特定功能。Defines the owner window procedure that is overridden to add specific functionality to a common dialog box.

(继承自 CommonDialog)
Reset()

将所有选项重新设置为其默认值。Resets all options to their default values.

RunDialog(IntPtr)

在派生类中被重写时,指定通用对话框。When overridden in a derived class, specifies a common dialog box.

(继承自 CommonDialog)
ShowDialog()

用默认的所有者运行通用对话框。Runs a common dialog box with a default owner.

(继承自 CommonDialog)
ShowDialog(IWin32Window)

运行具有指定所有者的通用对话框。Runs a common dialog box with the specified owner.

(继承自 CommonDialog)
ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)

事件

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)
HelpRequest

当用户单击通用对话框中的“帮助”按钮时发生。Occurs when the user clicks the Help button on a common dialog box.

(继承自 CommonDialog)

适用于

另请参阅