• 读书日记


    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 }
  • 相关阅读:
    Zend Studio下调试PHP的一点注意事项
    使用FTP出现中文乱码解决方案
    C++数据类型与C#对应表
    FineUI 开发B/S系统
    c#调用带输出参数的存储过程
    经典FormsAuthenticationTicket 分析
    C# Oracle数据库操作类实例详解
    如何使用C#的Hashtable[哈希表]
    对三层架构的理解
    C# 最简单的三层架构实例 ——转载自网易博客
  • 原文地址:https://www.cnblogs.com/WuXuanKun/p/5441679.html
Copyright © 2020-2023  润新知