首页 > Windows开发 > 详细

16.WinForm练习--保存对话框

时间:2019-05-22 22:05:16      阅读:119      评论:0      收藏:0      [点我收藏+]
namespace _16.保存对话框
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        //打开保存对话框
        SaveFileDialog sfd = new SaveFileDialog();
        //设置对话框属性
        sfd.Title = "请选择保存文件的路径";
        sfd.InitialDirectory = @"C:\Users\Administrator.USER-20180925HC\Desktop\pic";
        sfd.Filter = "文本文件|*.txt|所有文件|*.*";
        sfd.ShowDialog();

        //获得保存文件的路径
        string path = sfd.FileName;
        if (path == "")
        {
            return;
        }
        using(FileStream fsWrite=new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
        {
            byte[] buffer = Encoding.Default.GetBytes(textBox1.Text);
            fsWrite.Write(buffer, 0, buffer.Length);
        }
        MessageBox.Show("保存成功");

    }
}

}

16.WinForm练习--保存对话框

原文:https://blog.51cto.com/12679593/2398767

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!