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

发布时间:2020-08-02 10:24:01 作者:初禾
来源:网络 阅读:247

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("保存成功");

    }
}

}

推荐阅读:
  1. SHELL脚本练习
  2. group by 练习

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

保存对话框 fo --

上一篇:小白也能轻松上手的内网访问神器 NAS伴侣

下一篇:递归,二分法,匿名函数

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》