PageSetupDialog PageSetupDialog PageSetupDialog PageSetupDialog Class

定义

允许用户更改与页面相关的打印设置,包括边距和纸张方向。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使用PageSettingsPrinterSettings,和ShowNetwork属性。The following code example demonstrates the PageSetupDialog using the PageSettings, PrinterSettings, and ShowNetwork properties. 若要运行此示例,请将其放在一个窗体,其中包含Button名为Button1ListBox名为ListBox1,和一个PageSetupDialog名为PageSetupDialog1To 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对话框中修改PageSettingsPrinterSettings信息给定DocumentThe 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.

因为PageSetupDialog需要页设置,若要显示,您需要设置DocumentPrinterSettings,或PageSettings属性之前调用ShowDialog; 否则为将出现异常。Because 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() PageSetupDialog() PageSetupDialog()

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

属性

AllowMargins AllowMargins AllowMargins AllowMargins

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

AllowOrientation AllowOrientation AllowOrientation AllowOrientation

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

AllowPaper AllowPaper AllowPaper AllowPaper

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

AllowPrinter AllowPrinter AllowPrinter AllowPrinter

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

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

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

(Inherited from Component)
Container Container Container Container

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

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

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

(Inherited from Component)
Document Document Document Document

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

EnableMetric EnableMetric EnableMetric 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 Events Events Events

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

(Inherited from Component)
MinMargins MinMargins MinMargins MinMargins

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

PageSettings PageSettings PageSettings PageSettings

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

PrinterSettings PrinterSettings PrinterSettings PrinterSettings

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

ShowHelp ShowHelp ShowHelp ShowHelp

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

ShowNetwork ShowNetwork ShowNetwork ShowNetwork

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

Site Site Site Site

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

(Inherited from Component)
Tag Tag Tag Tag

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

(Inherited from CommonDialog)

方法

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

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

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

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

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

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

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

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

(Inherited from Component)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr)

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

(Inherited from CommonDialog)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs)

引发 HelpRequest 事件。Raises the HelpRequest event.

(Inherited from CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

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

(Inherited from CommonDialog)
Reset() Reset() Reset() Reset()

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

RunDialog(IntPtr) RunDialog(IntPtr) RunDialog(IntPtr) RunDialog(IntPtr)

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

(Inherited from CommonDialog)
ShowDialog() ShowDialog() ShowDialog() ShowDialog()

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

(Inherited from CommonDialog)
ShowDialog(IWin32Window) ShowDialog(IWin32Window) ShowDialog(IWin32Window) ShowDialog(IWin32Window)

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

(Inherited from CommonDialog)
ToString() ToString() ToString() ToString()

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

(Inherited from Component)

事件

Disposed Disposed Disposed Disposed

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

(Inherited from Component)
HelpRequest HelpRequest HelpRequest HelpRequest

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

(Inherited from CommonDialog)

适用于

另请参阅