1、此次问题出现的原因我估计是我是用了第三方的皮肤插件IrisSkin2造成的,当我点击按钮执行操作的时候FolderBrowserDialog中的ShowDialog()方法的值竟然是Cancel,好让我头疼啊,代码如下:
private void OpenFileSavePath_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "请选择文件夹";
if (fbd.ShowDialog() == DialogResult.OK)
{
if (string.IsNullOrEmpty(fbd.SelectedPath))
{
MessageBox.Show("文件夹路径不能为空!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
return;
}
this.lbl_fileSavePath.Text = fbd.SelectedPath;//存储文件的路径信息
}
}
如下图所示:
查了一下相关的资料:我们需要重新开一个线程单元去执行这些操作。最终完美的解决了这个问题,代码如下:
/// <summary>
/// 选择文件保存路径(操作运行代码)
/// @author 王伟
/// @date 2019-10-17 10:16
/// @weather 小雨转多云
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenFileSavePath_Click(object sender, EventArgs e)
{
Thread threadBySavePath = new Thread(SelectSavePath);
threadBySavePath.SetApartmentState(ApartmentState.STA);
threadBySavePath.Start();
}
/// <summary>
/// 选择文件保存路径(操作 执行代码)
/// @author 王伟
/// @date 2019-10-17 10:16
/// @weather 小雨转多云
/// </summary>
private void SelectSavePath()
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "请选择文件夹";
if (fbd.ShowDialog() == DialogResult.OK)
{
if (string.IsNullOrEmpty(fbd.SelectedPath))
{
MessageBox.Show("文件保存路径不能为空!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
return;
}
Action setValue = () =>{this.lbl_fileSavePath.Text = fbd.SelectedPath;};
this.lbl_fileSavePath.Invoke(setValue);//存储文件的路径信息
}
}
结束了,希望能帮到大家。有错误还请大家不吝赐教哦!!!!
感情有着极大的鼓舞力量,因此,它是一切道德行为的重要前提,谁要是没有强烈的志向,也就不能够热烈地把这个志向体现于事业中。 —— 凯洛夫