This is the first day of my participation in Gwen Challenge

function

The left group box is used to input student information (including student number, name, gender, age and score). When the user clicks “Add” command button, the current student information will be added to the specified text file. The grouping box on the right is used to display all the student records stored in the specified files to achieve a student information management system with few functions. The execution interface is shown as follows:

The program

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 file operation {public partial class Form1: Form {string path = "D:\ master.txt"; Public Form1() {InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int i; String mystr = "Student id \t\t name \t sex \t age \t score \r\n"; FileStream fs = File.OpenRead(path); StreamReader st = new StreamReader(fs, Encoding.GetEncoding("UTF-8")); // Initializes a new instance of the StreamReader class with the specified character encoding for the specified stream // specifies the open file fs.seek (0, seekOrigine.begin); While (st.peek () > -1) {mystr = mystr + st.readline (); mystr = mystr + "\r\n"; } st.Close(); fs.Close(); textBox1.Text = mystr; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void groupBox1_Enter(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { string str; if(! File.exists (path))// If it does not exist, create {StreamWriter sw = file.createText (path); sw.Close(); } if(textBox2.Text! ="") { str = textBox2.Text + "\t" + textBox3.Text + "\t" + textBox4.Text + "\t" + textBox5.Text + "\t" + textBox6.Text; StreamWriter sb = new StreamWriter(path,true,Encoding.UTF8); sb.WriteLine(str); sb.Close(); textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; button2.Enabled = false; textBox2.Focus(); } } private void textBox2_TextChanged(object sender, EventArgs e) { button2.Enabled = true; }}}Copy the code

Implementation effect

Student information can be input on the left, student information can be read on the right.