C# SaveDialog的一个问题
来源:百度知道 编辑:UC知道 时间:2024/05/26 05:29:23
SaveFileDialog sf = new SaveFileDialog();
sf.Title = "导出为:";
sf.InitialDirectory = "D:\\";
sf.Filter = "excel file(.xls)|*.xls|All file(*.*)|*.*";
sf.ShowDialog();
string sfName = sf.FileName;
if (sf.ShowDialog() == DialogResult.OK)
{
try
{
}
catch
{
throw new ArgumentException();
}
}
else
MessageBox.Show("你没有选择路径,请选择正确的存储路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
呵呵……我已经发现了这个问题了……
自己大意了点,不够细心!
不过还是谢谢了!
//sf.ShowDialog(); <---------把这句话注释掉,多余,你Show了两遍
string sfName = sf.FileName;
if (sf.ShowDialog() == DialogResult.OK)
……
注释掉一行就好了
sf.ShowDialog();其实在IF里也做了一次
SaveFileDialog sf = new SaveFileDialog();
sf.Title = "导出为:";
sf.InitialDirectory = "D:\\";
sf.Filter = "excel file(.xls)|*.xls|All file(*.*)|*.*";
//sf.ShowDialog();
string sfName = sf.FileName;
if (sf.ShowDialog() == DialogResult.OK)
{
try
{
}
catch
{
throw new ArgumentException();
}
}
else
MessageBox.Show("你没有选择路径,请选择正确的存储路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);