C#下载文件时候弹出选择文件夹保存目录的代码
//保存文件夹选择对话框引用
//添加引用system.design.dll /
using System.Windows.Forms.Design;
private void button4_Click(object sender, System.EventArgs e)
{
//选择文件的保存路径
//添加窗体控件folderBrowserDialog1
DirBrowser olderBrowserDlg=new DirBrowser();
if (folderBrowserDialog1.ShowDialog()==DialogResult.OK)
{
textBox2.Text = folderBrowserDialog1.SelectedPath;
}
}
#region 弹出保存文件夹选择窗口类
//一般选择文件保存地址都用弹出对话框来进行选择
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.StartLocati
相关新闻>>
- 发表评论
-
- 最新评论 更多>>