一般选择文件保存地址都用弹出对话框来进行选择,如下:
public class DirBrowser : FolderNameEditor
{
FolderBrowser fb = new FolderBrowser();
public string Description
{
set { _description = value; }
get { return _description; }
}
public string ReturnPath
{
get { return _returnPath; }
}
public DirBrowser() { }
public DialogResult ShowDialog()
{
fb.Description = _description;
fb.StartLocation = FolderBrowserFolder.MyComputer;
DialogResult r = fb.ShowDialog();
if (r == DialogResult.OK)
_returnPath = fb.DirectoryPath;
else
_returnPath = String.Empty;
return r;
} private string _description = "Choose Directory";
private string _returnPath = String.Empty;
}调用
DirBrowser myDirBrowser=new DirBrowser();
if(myDirBrowser.ShowDialog()!=DialogResult.Cancel)
MessageBox.Show(myDirBrowser.ReturnPath);To 怎样在Treeview中添加文件夹的浏览
那你需要在自己遍历目录进行添加(比较麻烦)。
public class DirBrowser : FolderNameEditor
{
FolderBrowser fb = new FolderBrowser();
public string Description
{
set { _description = value; }
get { return _description; }
}
public string ReturnPath
{
get { return _returnPath; }
}
public DirBrowser() { }
public DialogResult ShowDialog()
{
fb.Description = _description;
fb.StartLocation = FolderBrowserFolder.MyComputer;
DialogResult r = fb.ShowDialog();
if (r == DialogResult.OK)
_returnPath = fb.DirectoryPath;
else
_returnPath = String.Empty;
return r;
} private string _description = "Choose Directory";
private string _returnPath = String.Empty;
}调用
DirBrowser myDirBrowser=new DirBrowser();
if(myDirBrowser.ShowDialog()!=DialogResult.Cancel)
MessageBox.Show(myDirBrowser.ReturnPath);To 怎样在Treeview中添加文件夹的浏览
那你需要在自己遍历目录进行添加(比较麻烦)。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货