第1个回答 2018-01-16
private void btn_add_Click(object sender, EventArgs e)
{
string s = "姓名:";
s += textBox1.Text.Trim() + "\r\n";
s += "年龄:";
s += textBox2.Text.Trim() + "\r\n";
s += "成绩:";
s += textBox3.Text.Trim() + "\r\n";
FileStream fs = new FileStream(@"C:\\123.txt", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, s);
fs.Close();
}
private void btn_show_Click(object sender, EventArgs e)
{
try
{
FileStream fs = new FileStream(@"C:\\123.txt", FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
richTextBox1.Text = bf.Deserialize(fs).ToString();
}
catch
{
}
}本回答被提问者采纳