Re: [問題]C#和Folderbrowserdialog
※ 引述《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
11/04 14:59, 1F
推
11/04 15:03, , 2F
11/04 15:03, 2F
→
11/04 15:21, , 3F
11/04 15:21, 3F
→
11/04 15:22, , 4F
11/04 15:22, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):