SaveFileDialog SaveFileDialog SaveFileDialog SaveFileDialog Class

定义

提示用户选择文件的保存位置。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() SaveFileDialog() SaveFileDialog() SaveFileDialog()

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

属性

AddExtension AddExtension AddExtension 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.

(Inherited from FileDialog)
AutoUpgradeEnabled AutoUpgradeEnabled AutoUpgradeEnabled 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.

(Inherited from FileDialog)
CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

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

(Inherited from Component)
CheckFileExists CheckFileExists CheckFileExists 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.

(Inherited from FileDialog)
CheckPathExists CheckPathExists CheckPathExists CheckPathExists

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

(Inherited from FileDialog)
Container Container Container Container

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

(Inherited from Component)
CreatePrompt CreatePrompt CreatePrompt 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 CustomPlaces CustomPlaces CustomPlaces

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

(Inherited from FileDialog)
DefaultExt DefaultExt DefaultExt DefaultExt

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

(Inherited from FileDialog)
DereferenceLinks DereferenceLinks DereferenceLinks 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).

(Inherited from FileDialog)
DesignMode DesignMode DesignMode DesignMode

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

(Inherited from Component)
Events Events Events Events

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

(Inherited from Component)
FileName FileName FileName FileName

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

(Inherited from FileDialog)
FileNames FileNames FileNames FileNames

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

(Inherited from FileDialog)
Filter Filter Filter 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.

(Inherited from FileDialog)
FilterIndex FilterIndex FilterIndex FilterIndex

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

(Inherited from FileDialog)
InitialDirectory InitialDirectory InitialDirectory InitialDirectory

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

(Inherited from FileDialog)
Instance Instance Instance Instance

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

(Inherited from FileDialog)
Options Options Options Options

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

(Inherited from FileDialog)
OverwritePrompt OverwritePrompt OverwritePrompt 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 RestoreDirectory RestoreDirectory RestoreDirectory

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

(Inherited from FileDialog)
ShowHelp ShowHelp ShowHelp ShowHelp

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

(Inherited from FileDialog)
Site Site Site Site

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

(Inherited from Component)
SupportMultiDottedExtensions SupportMultiDottedExtensions SupportMultiDottedExtensions SupportMultiDottedExtensions

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

(Inherited from FileDialog)
Tag Tag Tag Tag

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

(Inherited from CommonDialog)
Title Title Title Title

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

(Inherited from FileDialog)
ValidateNames ValidateNames ValidateNames ValidateNames

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

(Inherited from FileDialog)

方法

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

(Inherited from FileDialog)
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)
OnFileOk(CancelEventArgs) OnFileOk(CancelEventArgs) OnFileOk(CancelEventArgs) OnFileOk(CancelEventArgs)

引发 FileOk 事件。Raises the FileOk event.

(Inherited from FileDialog)
OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs)

引发 HelpRequest 事件。Raises the HelpRequest event.

(Inherited from CommonDialog)
OpenFile() OpenFile() OpenFile() OpenFile()

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

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

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

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

(Inherited from FileDialog)
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()

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

(Inherited from FileDialog)

事件

Disposed Disposed Disposed Disposed

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

(Inherited from Component)
FileOk FileOk FileOk FileOk

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

(Inherited from FileDialog)
HelpRequest HelpRequest HelpRequest HelpRequest

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

(Inherited from CommonDialog)

适用于

另请参阅