通过C#语言编写一个winform窗体输出xml文件

文章目录

    • 代码内容
    • 最终效果

代码内容

C#代码部分

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WriteE_mail
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCantel_Click(object sender, EventArgs e)
        {
            Application.Exit();//退出程序
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string path = "Note.xml";//用来存放文件的路径
            FileStream fs = new FileStream(path,FileMode.Create);//创建文件流对象
            StreamWriter sw = new StreamWriter(fs);//创建写入器
            StringBuilder builder = new StringBuilder();//创建可变字符对象
            builder.AppendLine("");//追加行
            builder.AppendLine("");
            builder.AppendLine("");
            builder.AppendLine("{3}");
            builder.AppendLine("{4}");
            builder.AppendLine("{5}");
            builder.AppendLine("{6}");
            builder.AppendLine("");
            builder.AppendLine("");
            string show = string.Format(builder.ToString(), txtYY.Text, txtMM.Text, txtDD.Text,txtTo.Text, txtFrom.Text, txtHeading.Text, txtMessage.Text );
            sw.Write(show);//格式字符串
            sw.Close();//关闭写入流
            fs.Close();//关闭文件流
            DialogResult result = MessageBox.Show("生成文件成功!","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
            if (result==DialogResult.OK)
            {
                this.Close();//关闭当前的窗体
            }
        }
    }

}

窗体设计部分
通过C#语言编写一个winform窗体输出xml文件_第1张图片

最终效果

程序演示

通过C#语言编写一个winform窗体输出xml文件_第2张图片
通过C#语言编写一个winform窗体输出xml文件_第3张图片

通过C#语言编写一个winform窗体输出xml文件_第4张图片

生成的Note.xml


<Note>

<To>赵三儿To>
<From>李四儿From>
<Heading>吃饭Heading>
<Message>饭热好了,我知道你的身体不太好,要趁热吃Message>
Day>
Note>

你可能感兴趣的:(---其他的)