1.创建窗体
2.实现页面效果
3.编码
1 using System.IO; 2 3 namespace 读书日记 4 { 5 public partial class Form1 : Form 6 { 7 public Form1() 8 { 9 InitializeComponent();10 }11 12 private void button1_Click(object sender, EventArgs e)13 {14 string Author = textBox1.Text;15 string BookName = textBox2.Text;16 string Content = textBox3.Text;17 //把文件创建在E盘下18 string Path = "E:\\" + BookName + ".txt";19 //FileStream fs = new FileStream(Path, FileMode.Create);20 //StreamWriter sw = new StreamWriter(fs, Encoding.Default);21 //sw.WriteLine("作者{0}", Author);22 //sw.WriteLine("标题{0}",BookName);23 //sw.WriteLine("内容{0}",Content);24 //sw.Close();25 //fs.Close();26 //MessageBox.Show("保存成功!");27 //textBox1.Text = "";28 //textBox2.Text = "";29 //textBox3.Text = "";30 31 32 33 // 把文件写在bin目录下34 FileStream fs = new FileStream(Author + ".txt", FileMode.OpenOrCreate);35 StreamWriter sw = new StreamWriter(fs, Encoding.Default);36 sw.WriteLine(Author + " " + BookName + " " + Content);37 sw.Close();38 fs.Close();39 MessageBox.Show("保存成功!");40 41 }42 43 private void button2_Click(object sender, EventArgs e)44 {45 //Application.Exit();46 DialogResult result;47 result = MessageBox.Show("是否保存?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);48 if (result ==DialogResult .OK)49 {50 this.Close();51 }52 }53 }54 }