添加引用system.design.dll
//选择文件的保存路径
dirbrowser olderbrowserdlg=new dirbrowser();
if (folderbrowserdlg.showdialog()==dialogresult.ok)
{
txtfilepath.text = folderbrowserdlg.selectedpath;
}
//
using system.windows.forms.design;
using system.windows.forms;
using system;
//一般选择文件保存地址都用弹出对话框来进行选择
public class directoryselect : foldernameeditor
{
private folderbrowser fb = new folderbrowser();
private string fdescription = "choose directory";
private string freturnpath = string.empty;
public string description
{
set { fdescription = value; }
get { return fdescription; }
}
public string returnpath
{
get { return freturnpath; }
}
public directoryselect()
{
}
private dialogresult rundialog()
{
fb.description = this.description;
fb.startlocation = folderbrowserfolder.mycomputer;
fb.style = folderbrowserstyles.restricttosubfolders;
//|folderbrowserstyles.restricttodomain;
return fb.showdialog();
}
public dialogresult showdialog()
{
dialogresult dres = dialogresult.none;
dres = rundialog();
if (dres == dialogresult.ok)
this.freturnpath = fb.directorypath;
else
this.freturnpath = string.empty;
return dres;
}
}
//一般选择文件保存地址都用弹出对话框来进行选择
//调用
//dirbrowser mydirbrowser=new dirbrowser();
//if(mydirbrowser.showdialog()!=dialogresult.cancel)
//messagebox.show(mydirbrowser.returnpath);
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;
private string _description = "请选择文件夹";
private string _returnpath = string.empty;
}
新闻热点
疑难解答