WPF中的对话框(Dialog)

来源:互联网 发布:杨辉三角java代码递归 编辑:程序博客网 时间:2024/06/05 16:20

 在WPF中,系统定义的对话框(Dialog)有三种:

  (1)Microsoft.Win32.OpenFileDialog

  (2)Microsoft.Win32.SaveFileDialog

  (3)System.Windows.Controls.PrintDialog

  先看看前面两种的层次继承关系:

  System.Object

  Microsoft.Win32.CommonDialog

  Microsoft.Win32.FileDialog

  Microsoft.Win32.OpenFileDialog

  Microsoft.Win32.SaveFileDialog

  我们看到,这两种对话框均位于Microsoft.Win32命名空间中,它们均继承自Microsoft.Win32.FileDialog。

  (1)OpenFileDialog:

  OpenFileDialog有一种公共事件:FileOk(当用户选择文件名,点击打开按钮时发生)

  OpenFileDialog有以下几种公共方法:

  OpenFile():打开单个文件

  OpenFiles():打开多个文件

  Reset():重置

  ShowDialog():显示对话框

  OpenFileDialog的公共属性有:

  .AddExtension,

  .CheckFileExists,

  .CheckPathExists,

  .DefaultExt,

  .DereferenceLinks,

  .FileName,

  .FileNames,

  .Filter,

  .FilterIndex,

  .InitialDirectory,

  .Multiselect,

  .ReadOnlyChecked,

  .RestoreDirectory,

  .SafeFileName,

  .SafeFileNames,

  .ShowReadOnly,

  .Tag,

  .Title,

  .ValidateNames

  其中,我们最常用的有: FileName, FileNames, Filter, FilterIndex, DefaultExt,InitialDirectory等。

  (2) SaveFileDialog:

  与OpenFileDialog类似,SaveFileDialog公共方法:

  OpenFile()

  Reset()

  ShowDialog()

  公共属性:

  .AddExtension,

  .CheckFileExists,

  .CheckPathExists,

  .CreatePrompt,

  .DefaultExt,

  .DereferenceLinks,

  .FileName,

  .FileNames,

  .Filter,

  .FilterIndex,

  .InitialDirectory,

  .OverwritePrompt,

  .RestoreDirectory,

  .SafeFileName,

  .SafeFileNames,

  .Tag,

  .Title,

  .ValidateNames

  说明:在WPF中的Microsoft.Win32.OpenFileDialog,Microsoft.Win32.SaveFileDialog与在WinForm中的System.Windows.Forms.OpenFileDialog, System.Windows.Forms.SaveFileDialog用法上基本上一样,但前者由于WPF的限制,无法在Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE下使用。

  再看看看PrintDialog:

  (3)PrintDialog:

  看看它的继承关系:

  System.Object

  System.Windows.Controls.PrintDialog

  需要注意的是:不要将System.Windows.Controls.PrintDialog与System.Windows.Forms.PrintDialog混淆了,后者用于WinForm应用程序中。System.Windows.Controls.PrintDialog则用于Windows Presentation Foundation (WPF)应用程序中。

本文来自wuzhengqing1的博客,原文地址:http://blog.csdn.net/wuzhengqing1/archive/2011/05/10/6410428.aspx

原创粉丝点击