FileOk 當用戶點擊"打開"或"保存"按鈕時要處理的事件
HelpRequest 當用戶點擊"幫助"按鈕時要處理的事件spa
能夠用如下代碼來實現上面這個對話框:code
private void openFileDialogBTN_Click(object sender, System.EventArgs e) { OpenFileDialog openFileDialog=new OpenFileDialog(); openFileDialog.InitialDirectory="c:\\";//注意這裏寫路徑時要用c:\\而不是c:\ openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|全部文件|*.*"; openFileDialog.RestoreDirectory=true; openFileDialog.FilterIndex=1; if (openFileDialog.ShowDialog()==DialogResult.OK) { fName=openFileDialog.FileName; File fileOpen=new File(fName); isFileHaveName=true; richTextBox1.Text=fileOpen.ReadFile(); richTextBox1.AppendText(""); } }
openfiledialog.FileName //獲取或設置一個包含在文件對話框中選定的文件名字符串blog
openfiledialog.SafeFileName //獲取選定對話框中的文件名和擴展名索引
FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "請選擇文件路徑"; if (dialog.ShowDialog() == DialogResult.OK) { savePath = dialog.SelectedPath; textBox2.Text = savePath; }