Winform另存为

发布于 2024-10-18 04:50:41 字数 89 浏览 6 评论 0原文

有谁知道任何文章或网站显示如何在 win 表单中创建“另存为”对话框。我有一个按钮,用户单击并序列化一些数据,然后用户使用此“另存为”框指定他们希望将其保存的位置。

Does anyone know any articles or sites showing how to create a "Save as" dialogue box in win forms. I have a button, user clicks and serializes some data, the user than specifies where they want it saved using this Save as box.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绅刃 2024-10-25 04:50:41

您的意思是像 SaveFileDialog 吗?

来自MSDN示例,稍作修改:

using (SaveFileDialog dialog = new SaveFileDialog())
{
    dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
    dialog.FilterIndex = 2 ;
    dialog.RestoreDirectory = true ;

    if (dialog.ShowDialog() == DialogResult.OK)
    {
        // Can use dialog.FileName
        using (Stream stream = dialog.OpenFile())
        {
            // Save data
        }
    }
}

You mean like SaveFileDialog?

From the MSDN sample, slightly amended:

using (SaveFileDialog dialog = new SaveFileDialog())
{
    dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
    dialog.FilterIndex = 2 ;
    dialog.RestoreDirectory = true ;

    if (dialog.ShowDialog() == DialogResult.OK)
    {
        // Can use dialog.FileName
        using (Stream stream = dialog.OpenFile())
        {
            // Save data
        }
    }
}
弥繁 2024-10-25 04:50:41

使用SaveFileDialog 控制/类。

Use the SaveFileDialog control/class.

习ぎ惯性依靠 2024-10-25 04:50:41

我在 C# 中做了一个记事本应用程序,我遇到了这个场景来保存文件,尝试一下。它会完美地工作

 private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
    {

        SaveFileDialog saveFileDialog1 = new SaveFileDialog();

        saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
        saveFileDialog1.FilterIndex = 2;
        saveFileDialog1.RestoreDirectory = true;

        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {


            System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName.ToString());
            file.WriteLine(richTextBox1.Text);
            file.Close();
        }



    }

Im doing a notepad application in c# i came over this scenario to save file as try this out.It will work perfectly

 private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
    {

        SaveFileDialog saveFileDialog1 = new SaveFileDialog();

        saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
        saveFileDialog1.FilterIndex = 2;
        saveFileDialog1.RestoreDirectory = true;

        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {


            System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName.ToString());
            file.WriteLine(richTextBox1.Text);
            file.Close();
        }



    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文