C#使用瀏覽按鈕獲得文件路徑和文件夾路徑的方法是什么?這個(gè)問(wèn)題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見(jiàn)到的。希望通過(guò)這個(gè)問(wèn)題能讓你收獲頗深。下面是小編給大家?guī)?lái)的參考內(nèi)容,讓我們一起來(lái)看看吧!
生成文件夾路徑
private void btnChoose_Click(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Multiselect = true; if (dialog.ShowDialog() == DialogResult.OK) { try { this.tbFilePath.Text = dialog.FileName; } catch(Exception ex) { throw(ex); } } }
生成文件路徑
新建一個(gè)FolderDialog類(重載FolderNameEditor)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms.Design; using System.Windows.Forms; namespace Common { class FolderDialog:FolderNameEditor { FolderBrowser fDialog = new FolderBrowser(); public FolderDialog(){ } public DialogResult DisplayDialog() { return DisplayDialog("請(qǐng)選擇一個(gè)文件夾"); } public DialogResult DisplayDialog(string description) { fDialog.Description = description; return fDialog.ShowDialog(); } public string Path { get { return fDialog.DirectoryPath; } } ~FolderDialog() { fDialog.Dispose(); } } }
瀏覽按鈕下的事件
private void btnChoose_Click(object sender, EventArgs e) { FolderDialog fDialog = new FolderDialog(); fDialog.DisplayDialog(); this.tbfilePath.Text = fDialog.Path; }
感謝各位的閱讀!看完上述內(nèi)容,你們對(duì)C#使用瀏覽按鈕獲得文件路徑和文件夾路徑的方法是什么大概了解了嗎?希望文章內(nèi)容對(duì)大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
新聞標(biāo)題:C#使用瀏覽按鈕獲得文件路徑和文件夾路徑的方法是什么-創(chuàng)新互聯(lián)
文章鏈接:http://sd-ha.com/article20/ihcjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、定制開發(fā)、電子商務(wù)、響應(yīng)式網(wǎng)站、網(wǎng)站導(dǎo)航、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容