OpenFileDialog 類別

定義

代表一個常見的對話框,允許使用者指定一個或多個檔案的檔名以開啟。

public ref class OpenFileDialog sealed : Microsoft::Win32::FileDialog
public sealed class OpenFileDialog : Microsoft.Win32.FileDialog
type OpenFileDialog = class
    inherit FileDialog
Public NotInheritable Class OpenFileDialog
Inherits FileDialog
繼承
OpenFileDialog
繼承

範例

以下範例說明如何建立包含預設檔名與副檔名類型的 檔案 OpenFileDialog

// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension

// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();

// Process open file dialog box results
if (result.Value)
{
    // Open document
    string filename = dlg.FileName;
}
' Configure open file dialog box
Dim dlg As New Microsoft.Win32.OpenFileDialog()
dlg.FileName = "Document" ' Default file name
dlg.DefaultExt = ".txt" ' Default file extension
dlg.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension

' Show open file dialog box
Dim result? As Boolean = dlg.ShowDialog()

' Process open file dialog box results
If result = True Then
    ' Open document
    Dim filename As String = dlg.FileName
End If

備註

你無法在 XAML 中宣告這個管理類別。

建構函式

名稱 Description
OpenFileDialog()

初始化 OpenFileDialog 類別的新執行個體。

屬性

名稱 Description
AddExtension

取得或設定一個值,指示若使用者遺漏副檔名,檔案對話框是否自動為檔名加上副檔名。

(繼承來源 FileDialog)
AddToRecent

取得或設定一個值,指示對話框是否會將正在開啟或儲存的項目加入最近文件清單。

(繼承來源 CommonItemDialog)
CheckFileExists

會取得或設定一個值,指示若使用者指定不存在的檔名,檔案對話框是否會顯示警告。

(繼承來源 FileDialog)
CheckPathExists

取得或設定一個值,指定若使用者輸入無效路徑與檔案名稱,是否會顯示警告。

(繼承來源 FileDialog)
ClientGuid

取得或設定一個 GUID,以關聯對話框的持久狀態。

(繼承來源 CommonItemDialog)
CustomPlaces

取得或設定檔案對話框的自訂位置清單。

(繼承來源 FileDialog)
DefaultDirectory

若檔案對話框中沒有最近使用的目錄值可用,則會取得或設定該目錄。

(繼承來源 CommonItemDialog)
DefaultExt

取得或設定一個值,指定預設的副檔名字串,用以篩選顯示的檔案清單。

(繼承來源 FileDialog)
DereferenceLinks

取得或設定一個值,指示檔案對話框是回傳捷徑所參考的檔案位置,還是捷徑檔案(.lnk)的位置。

(繼承來源 FileDialog)
FileName

取得或設定包含檔案對話框中所選檔案完整路徑的字串。

(繼承來源 FileDialog)
FileNames

會得到一個陣列,每個選擇檔案都包含一個檔案名稱。

(繼承來源 FileDialog)
Filter

取得或設定過濾字串,決定從 或 OpenFileDialog中顯示SaveFileDialog哪些類型的檔案。

(繼承來源 FileDialog)
FilterIndex

取得或設定目前在檔案對話框中選取的過濾器索引。

(繼承來源 FileDialog)
ForcePreviewPane

會觸發或設定一個選項旗標,指示對話框是否強制開啟預覽窗格。

InitialDirectory

取得或設定由檔案對話框顯示的初始目錄。

(繼承來源 FileDialog)
Multiselect

會設定一個選項,指示使用者是否 OpenFileDialog 允許選擇多個檔案。

Options

取得 Win32 常見檔案對話框的旗標,這些標誌用於檔案對話框的初始化。

(繼承來源 FileDialog)
ReadOnlyChecked

取得或設定一個值,指示是否選擇了顯示的 OpenFileDialog 唯讀勾選框。

RestoreDirectory

此特性未被實作。

(繼承來源 FileDialog)
RootDirectory

取得或設定顯示為對話框導航根的目錄。

(繼承來源 CommonItemDialog)
SafeFileName

會得到一個只包含所選檔案檔名的字串。

(繼承來源 FileDialog)
SafeFileNames

會獲得一個陣列,每個選擇的檔案都包含一個安全的檔案名稱。

(繼承來源 FileDialog)
ShowHiddenItems

會取得或設定一個值,指示對話框是否會顯示隱藏項目與系統項目,無論使用者偏好如何。

(繼承來源 CommonItemDialog)
ShowReadOnly

取得或設定一個值,指示是否 OpenFileDialog 包含唯讀勾選框。

Tag

取得或設定與對話對話相關聯的物件。 這提供了將任意物件附加到對話框的功能。

(繼承來源 CommonDialog)
Title

取得或設定檔案對話框標題欄中的文字。

(繼承來源 FileDialog)
ValidateNames

會取得或設定一個值,指示對話框是否只接受有效的 Win32 檔案名稱。

(繼承來源 FileDialog)

方法

名稱 Description
CheckPermissionsToShowDialog()

判斷是否有足夠的權限顯示對話對話。

(繼承來源 CommonDialog)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

定義了常見的檔案對話框掛鉤程序,該程序會被覆寫以增加檔案對話框的共同功能。

(繼承來源 FileDialog)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
OnFileOk(CancelEventArgs)

引發 FileOk 事件。

(繼承來源 FileDialog)
OnItemOk(CancelEventArgs)

引發 FileOk 事件。

(繼承來源 FileDialog)
OpenFile()

為使用者 OpenFileDialog選擇的檔案開啟一個唯讀串流。

OpenFiles()

建立一個陣列,為使用者 OpenFileDialog選擇的每個檔案建立一個只讀串流。

Reset()

將所有 OpenFileDialog 屬性重置為預設值。

RunDialog(IntPtr)

RunDialog(IntPtr) 被呼叫來顯示衍生類別中的檔案對話框,例如 OpenFileDialogSaveFileDialog

(繼承來源 FileDialog)
ShowDialog()

顯示共同對話。

(繼承來源 CommonDialog)
ShowDialog(Window)

顯示共同對話。

(繼承來源 CommonDialog)
ToString()

回傳一個字串,代表檔案對話框。

(繼承來源 FileDialog)

事件

名稱 Description
FileOk

當使用者點擊 的OpenFileDialog按鈕或儲存SaveFileDialog按鈕選擇檔案名稱時,會發生。

(繼承來源 FileDialog)

適用於

另請參閱