Re: [問題]C#和Folderbrowserdialog

看板C_Sharp作者 (睡魔)時間14年前 (2009/11/03 14:19), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《aahhmm (好好準備研究所囉~~)》之銘言: : 各位好,想請問有關wpf與Folderbrowserdialog這個函式使用之間的問題。 : 在板上發問前,我有先行google過了,也有找到相關的網頁,但是幾經測試, : 依舊無功而返,所以來請教各位。 : Folderbrowserdialog,這個函式是必須由Windows.Form來呼叫,但是WPF並不 : 支援,我在網路上有找到幾個相關的網頁,但是不甚了解其內容。不知道是否 : 有網友能夠幫忙解決。 : http://ppt.cc/BcFS : http://ppt.cc/0Tzc : 目前遇到的問題是完全無法執行,會出現錯誤。不知道該如何解決,若板友知 : 道該如何處理,請板友賜教^^!! 1) 新增一個class叫FolderDialog.cs (可能需要新增System.Windows.Form的 reference): using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace DlgApp { public class FolderDialog: Microsoft.Win32.CommonDialog { private string _path = null; public string Path { get { return this._path; } set { this._path = value; } } protected override bool RunDialog(IntPtr hwndOwner) { System.Windows.Forms.FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog(System.Windows.Forms.Form.FromHandle(hwndOwner)) == DialogResult.OK) { this._path = fbd.SelectedPath; return true; } return false; } public override void Reset() { this.Path = null; } } } 之後用這方式使用就可以了... private void bt_test_Click(object sender, RoutedEventArgs e) { FolderDialog fd = new FolderDialog(); if (fd.ShowDialog(this) == true) { this.lbl_path.Content = fd.Path; } } 請視需要增刪... -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.73.22.30

11/04 14:59, , 1F
推你一個! Good job!
11/04 14:59, 1F

11/04 15:03, , 2F
請問該怎麼加Reference呢?
11/04 15:03, 2F

11/04 15:21, , 3F
在Solution Explorer的Reference右擊, 然後
11/04 15:21, 3F

11/04 15:22, , 4F
Add Reference... 啊.
11/04 15:22, 4F
文章代碼(AID): #1AxyjWRn (C_Sharp)
文章代碼(AID): #1AxyjWRn (C_Sharp)