SaveFileDialog 类

定义

提示用户选择文件的保存位置。Prompts the user to select a location for saving a file. 此类不能被继承。This class cannot be inherited.

public ref class SaveFileDialog sealed : System::Windows::Forms::FileDialog
public sealed class SaveFileDialog : System.Windows.Forms.FileDialog
type SaveFileDialog = class
    inherit FileDialog
Public NotInheritable Class SaveFileDialog
Inherits FileDialog
继承

示例

下面的代码示例演示如何创建SaveFileDialog、设置成员、 ShowDialog使用方法调用对话框, 以及保存当前文件。The following code example illustrates creating a SaveFileDialog, setting members, calling the dialog box using the ShowDialog method, and saving the current file. 该示例需要一个带有按钮的窗体。The example requires a form with a button placed on it.

private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      Stream^ myStream;
      SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
      saveFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
      saveFileDialog1->FilterIndex = 2;
      saveFileDialog1->RestoreDirectory = true;
      if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
      {
         if ( (myStream = saveFileDialog1->OpenFile()) != nullptr )
         {
            
            // Code to write the stream goes here.
            myStream->Close();
         }
      }
   }

private void button1_Click(object sender, System.EventArgs e)
 {
     Stream myStream ;
     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
 
     saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
     saveFileDialog1.FilterIndex = 2 ;
     saveFileDialog1.RestoreDirectory = true ;
 
     if(saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         if((myStream = saveFileDialog1.OpenFile()) != null)
         {
             // Code to write the stream goes here.
             myStream.Close();
         }
     }
 }

Private Sub button1_Click(sender As Object, e As System.EventArgs)
    Dim myStream As Stream
    Dim saveFileDialog1 As New SaveFileDialog()
    
    saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    saveFileDialog1.FilterIndex = 2
    saveFileDialog1.RestoreDirectory = True
    
    If saveFileDialog1.ShowDialog() = DialogResult.OK Then
        myStream = saveFileDialog1.OpenFile()
        If (myStream IsNot Nothing) Then
            ' Code to write the stream goes here.
            myStream.Close()
        End If
    End If
End Sub

注解

此类可以打开和覆盖现有文件, 也可以创建新的文件。This class can either open and overwrite an existing file or create a new file.

此类的大部分功能都可在FileDialog类中找到。Most of the functionality for this class is found in the FileDialog class.

构造函数

SaveFileDialog()

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

属性

AddExtension

获取或设置一个值,该值指示如果用户省略扩展名,对话框是否自动在文件名中添加扩展名。Gets or sets a value indicating whether the dialog box automatically adds an extension to a file name if the user omits the extension.

(继承自 FileDialog)
AutoUpgradeEnabled

获取或设置一个值,该值指示此 FileDialog 实例在 Windows VistaWindows Vista 上运行时是否应自动升级外观和行为。Gets or sets a value indicating whether this FileDialog instance should automatically upgrade appearance and behavior when running on Windows VistaWindows Vista.

(继承自 FileDialog)
CanRaiseEvents

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

(继承自 Component)
CheckFileExists

获取或设置一个值,该值指示如果用户指定不存在的文件名,对话框是否显示警告。Gets or sets a value indicating whether the dialog box displays a warning if the user specifies a file name that does not exist.

(继承自 FileDialog)
CheckPathExists

获取或设置一个值,该值指示如果用户指定不存在的路径,对话框是否显示警告。Gets or sets a value indicating whether the dialog box displays a warning if the user specifies a path that does not exist.

(继承自 FileDialog)
Container

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

(继承自 Component)
CreatePrompt

获取或设置一个值,该值指示如果用户指定不存在的文件,对话框是否提示用户允许创建该文件。Gets or sets a value indicating whether the dialog box prompts the user for permission to create a file if the user specifies a file that does not exist.

CustomPlaces

获取此 FileDialog 实例的自定义空间的集合。Gets the custom places collection for this FileDialog instance.

(继承自 FileDialog)
DefaultExt

获取或设置默认文件扩展名。Gets or sets the default file name extension.

(继承自 FileDialog)
DereferenceLinks

获取或设置一个值,该值指示对话框是否返回快捷方式引用的文件的位置,或者是否返回快捷方式 (.lnk) 的位置。Gets or sets a value indicating whether the dialog box returns the location of the file referenced by the shortcut or whether it returns the location of the shortcut (.lnk).

(继承自 FileDialog)
DesignMode

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

(继承自 Component)
Events

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

(继承自 Component)
FileName

获取或设置一个包含在文件对话框中选定的文件名的字符串。Gets or sets a string containing the file name selected in the file dialog box.

(继承自 FileDialog)
FileNames

获取对话框中所有选定文件的文件名。Gets the file names of all selected files in the dialog box.

(继承自 FileDialog)
Filter

获取或设置当前文件名筛选器字符串,该字符串决定对话框的“另存为文件类型”或“文件类型”框中出现的选择内容。Gets or sets the current file name filter string, which determines the choices that appear in the "Save as file type" or "Files of type" box in the dialog box.

(继承自 FileDialog)
FilterIndex

获取或设置文件对话框中当前选定筛选器的索引。Gets or sets the index of the filter currently selected in the file dialog box.

(继承自 FileDialog)
InitialDirectory

获取或设置文件对话框显示的初始目录。Gets or sets the initial directory displayed by the file dialog box.

(继承自 FileDialog)
Instance

获取应用程序的 Win32 实例句柄。Gets the Win32 instance handle for the application.

(继承自 FileDialog)
Options

获取用来初始化 FileDialog 的值。Gets values to initialize the FileDialog.

(继承自 FileDialog)
OverwritePrompt

获取或设置一个值,该值指示如果用户指定的文件名已存在,Save As 对话框是否显示警告。Gets or sets a value indicating whether the Save As dialog box displays a warning if the user specifies a file name that already exists.

RestoreDirectory

获取或设置一个值,该值指示该对话框在关闭前是否将目录还原为之前选定的目录。Gets or sets a value indicating whether the dialog box restores the directory to the previously selected directory before closing.

(继承自 FileDialog)
ShowHelp

获取或设置一个值,该值指示文件对话框中是否显示“帮助”按钮。Gets or sets a value indicating whether the Help button is displayed in the file dialog box.

(继承自 FileDialog)
Site

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

(继承自 Component)
SupportMultiDottedExtensions

获取或设置对话框是否支持显示和保存具有多个文件扩展名的文件。Gets or sets whether the dialog box supports displaying and saving files that have multiple file name extensions.

(继承自 FileDialog)
Tag

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

(继承自 CommonDialog)
Title

获取或设置文件对话框标题。Gets or sets the file dialog box title.

(继承自 FileDialog)
ValidateNames

获取或设置一个值,该值指示对话框是否只接受有效的 Win32 文件名。Gets or sets a value indicating whether the dialog box accepts only valid Win32 file names.

(继承自 FileDialog)

方法

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 the file dialog box.

(继承自 FileDialog)
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)
OnFileOk(CancelEventArgs)

引发 FileOk 事件。Raises the FileOk event.

(继承自 FileDialog)
OnHelpRequest(EventArgs)

引发 HelpRequest 事件。Raises the HelpRequest event.

(继承自 CommonDialog)
OpenFile()

打开用户选定的具有读/写权限的文件。Opens the file with read/write permission selected by the user.

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 dialog box options to their default values.

RunDialog(IntPtr)

指定通用对话框。Specifies a common dialog box.

(继承自 FileDialog)
ShowDialog()

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

(继承自 CommonDialog)
ShowDialog(IWin32Window)

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

(继承自 CommonDialog)
ToString()

提供此对象的字符串版本。Provides a string version of this object.

(继承自 FileDialog)

事件

Disposed

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

(继承自 Component)
FileOk

当用户单击文件对话框中的“打开”或 “保存”按钮时发生。Occurs when the user clicks on the Open or Save button on a file dialog box.

(继承自 FileDialog)
HelpRequest

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

(继承自 CommonDialog)

适用于

另请参阅