SaveFileDialog Class

Definition

提示使用者選取儲存檔案的位置。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
Inheritance

Examples

下列程式碼範例說明如何建立 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

Remarks

這個類別可以開啟並覆寫現有的檔案,或建立新的檔案。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.

Constructors

SaveFileDialog()

初始化這個類別的新執行個體。Initializes a new instance of this class.

Properties

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

取得或設定值,指出此 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

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

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

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

(Inherited from FileDialog)
ClientGuid (Inherited from FileDialog)
Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

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

(Inherited from FileDialog)
DefaultExt

取得或設定預設的副檔名。Gets or sets the default file name extension.

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

(Inherited from FileDialog)
DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
FileName

取得或設定含有檔案對話方塊中所選取檔名的字串。Gets or sets a string containing the file name selected in the file dialog box.

(Inherited from FileDialog)
FileNames

取得對話方塊中所有選取檔案的檔名。Gets the file names of all selected files in the dialog box.

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

(Inherited from FileDialog)
FilterIndex

取得或設定檔案對話方塊中目前所選取之篩選條件的索引。Gets or sets the index of the filter currently selected in the file dialog box.

(Inherited from FileDialog)
InitialDirectory

取得或設定檔案對話方塊所顯示的初始目錄。Gets or sets the initial directory displayed by the file dialog box.

(Inherited from FileDialog)
Instance

取得應用程式的 Win32 執行個體控制代碼 (Instance Handle)。Gets the Win32 instance handle for the application.

(Inherited from FileDialog)
Options

取得值來初始化 FileDialogGets values to initialize the FileDialog.

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

(Inherited from FileDialog)
ShowHelp

取得或設定值,指出是否在 [檔案] 對話方塊中顯示 [說明] 按鈕。Gets or sets a value indicating whether the Help button is displayed in the file dialog box.

(Inherited from FileDialog)
Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
SupportMultiDottedExtensions

取得或設定對話方塊是否支援顯示和儲存具有多個副檔名的檔案。Gets or sets whether the dialog box supports displaying and saving files that have multiple file name extensions.

(Inherited from FileDialog)
Tag

取得或設定包含控制項相關資料的物件。Gets or sets an object that contains data about the control.

(Inherited from CommonDialog)
Title

取得或設定檔案對話方塊的標題。Gets or sets the file dialog box title.

(Inherited from FileDialog)
ValidateNames

取得或設定值,指出對話方塊是否只接受有效的 Win32 檔名。Gets or sets a value indicating whether the dialog box accepts only valid Win32 file names.

(Inherited from FileDialog)

Methods

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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()

釋出 Component 所使用的全部資源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

釋放 Component 所使用的 unmanaged 資源並選擇性地釋放 managed 的資源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

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

定義為了將特定功能加入檔案對話方塊中而覆寫的通用對話方塊攔截程序 (Hook Procedure)。Defines the common dialog box hook procedure that is overridden to add specific functionality to the file dialog box.

(Inherited from FileDialog)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnFileOk(CancelEventArgs)

引發 FileOk 事件。Raises the FileOk event.

(Inherited from FileDialog)
OnHelpRequest(EventArgs)

引發 HelpRequest 事件。Raises the HelpRequest event.

(Inherited from CommonDialog)
OpenFile()

開啟含使用者選取的讀取/寫入使用權限的檔案。Opens the file with read/write permission selected by the user.

OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

定義為了將特定功能加入通用對話方塊中而覆寫的主控視窗 (Owner Window) 程序。Defines the owner window procedure that is overridden to add specific functionality to a common dialog box.

(Inherited from CommonDialog)
Reset()

將所有對話方塊選項重設為預設值。Resets all dialog box options to their default values.

RunDialog(IntPtr)

指定通用對話方塊。Specifies a common dialog box.

(Inherited from FileDialog)
ShowDialog()

以預設的擁有人來執行通用對話方塊。Runs a common dialog box with a default owner.

(Inherited from CommonDialog)
ShowDialog(IWin32Window)

以指定的擁有人來執行通用對話方塊。Runs a common dialog box with the specified owner.

(Inherited from CommonDialog)
ToString()

提供這個物件的字串版本。Provides a string version of this object.

(Inherited from FileDialog)

Events

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
FileOk

發生於使用者按一下 [檔案] 對話方塊上的 [開啟] 或 [儲存] 按鈕時。Occurs when the user clicks on the Open or Save button on a file dialog box.

(Inherited from FileDialog)
HelpRequest

發生於使用者按一下通用對話方塊上的 [說明] 按鈕時。Occurs when the user clicks the Help button on a common dialog box.

(Inherited from CommonDialog)

Applies to

See also