作者leicheong (睡魔)
看板C_Sharp
标题Re: [问题]C#和Folderbrowserdialog
时间Tue Nov 3 14:19:09 2009
※ 引述《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
1F:推 tomnelson:推你一个! Good job! 11/04 14:59
2F:推 aahhmm:请问该怎麽加Reference呢? 11/04 15:03
3F:→ leicheong:在Solution Explorer的Reference右击, 然後 11/04 15:21
4F:→ leicheong:Add Reference... 啊. 11/04 15:22