读书日记

 2023-09-05 阅读 52 评论 0

摘要: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 &#

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

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/1155.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息