读书日记

本文介绍了一个使用C#编写的简单读书笔记应用程序。该程序允许用户输入书籍的作者、书名和内容,并将这些信息保存到本地文件中。此外,程序还提供了退出确认功能。

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 }

 

转载于:https://www.cnblogs.com/WuXuanKun/p/5441679.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值