使用按钮控件:Button
弹出选择文件夹
// 选择文件夹
public string select_paper_file()
{
string path = string.Empty;
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
path = fbd.SelectedPath;
return path;
}
return "";
}
弹出选择文件
// 选择文件
public string select_file()
{
string file = "";
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = false; //该值确定是否可以选择多个文件
dialog.Title = "请选择文件"; //弹窗的标题
//dialog.InitialDirectory = "D:\\"; //默认打开的文件夹的位置
// dialog.Filter = "MicroSoft Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*"; //筛选文件
//dialog.ShowHelp = true; //是否显示“帮助”按钮
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
file = dialog.FileName;
return file;
}
return file;
}