【问题标题】:How to get windows form saveFileDialog directory如何获取windows表单saveFileDialog目录
【发布时间】:2014-11-07 20:48:47
【问题描述】:

我想将我的图像保存到用户选择的文件夹中。我知道我可以使用流输出。但似乎更容易从 windows 提供的保存文件对话框中获取用户选择的路径,然后在 Image 类的保存函数中使用该路径。

Image img1;
String path;
...

private void button2_Click(object sender, EventArgs e)
{
    SaveFileDialog saveFileDialog1 = new SaveFileDialog();

    // Directory to open when saving files
    saveFileDialog1.InitialDirectory = path;
    // Sets the title of your dialog box
    saveFileDialog1.Title = "Save";
    // Sets the file type to filter out
    saveFileDialog1.Filter = "png files (*.png)|*.png|All files (*.*)|*.*";
    saveFileDialog1.FilterIndex = 2;
    //Destroys file when done if set to false
    saveFileDialog1.RestoreDirectory = true; 

    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    {
        try
        {
            img1.Save(HERE);             
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: Could not save file too disk. " + ex.Message);
        }
    }
}

我用“HERE”表示字符串目录路径的位置。

【问题讨论】:

  • 您查看过SaveFileDialog 的文档吗?
  • 有时Google 会很有帮助。

标签: c# winforms


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    相关资源
    最近更新 更多