private void button5_Click(object sender, EventArgs e)
{
SaveFileDialog test = new SaveFileDialog();
test.Filter = "二进制文件(.bin)| *.bin";
Worker wor = new Worker();
wor.ID = textBoxID.Text;
wor.Name = textBoxName.Text;
wor.Sex = comboBoxSex.SelectedItem.ToString();
wor.Bitrhday = dateTimePickerBirthday.Text.ToString();
wor.Constellation = (Constellations)Enum.Parse(typeof(Constellations), comboBoxConstellation.SelectedItem.ToString());
wor.Result = listBoxInfo.Text;
IFormatter formatter = new BinaryFormatter();
DialogResult res = test.ShowDialog();
if (res == DialogResult.OK)
{
Stream stream = new FileStream(test.FileName, FileMode.Create, FileAccess.Write);
formatter.Serialize(stream, wor);
} } private void button7_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "二进制文件(.bin)| *.bin";
ArrayList worklist = new ArrayList();
Worker wor = new Worker();
wor.ID = textBoxID.Text;
wor.Name = textBoxName.Text;
wor.Sex = comboBoxSex.SelectedItem.ToString();
wor.Bitrhday = dateTimePickerBirthday.Text.ToString();
wor.Constellation = (Constellations)Enum.Parse(typeof(Constellations), comboBoxConstellation.SelectedItem.ToString());
worklist.Add(wor);
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(open.FileName, FileMode.Open, FileAccess.Read);
DialogResult res=open.ShowDialog();
ArrayList loadlist = (ArrayList)formatter.Deserialize(stream);
if (res == DialogResult.OK)
{
loadlist.Add(wor);
}
}想要让一个listbox中显示序列化的内容 控件中包括导入(反序列化)导出(序列化),
谢谢各位帮忙了
{
SaveFileDialog test = new SaveFileDialog();
test.Filter = "二进制文件(.bin)| *.bin";
Worker wor = new Worker();
wor.ID = textBoxID.Text;
wor.Name = textBoxName.Text;
wor.Sex = comboBoxSex.SelectedItem.ToString();
wor.Bitrhday = dateTimePickerBirthday.Text.ToString();
wor.Constellation = (Constellations)Enum.Parse(typeof(Constellations), comboBoxConstellation.SelectedItem.ToString());
wor.Result = listBoxInfo.Text;
IFormatter formatter = new BinaryFormatter();
DialogResult res = test.ShowDialog();
if (res == DialogResult.OK)
{
Stream stream = new FileStream(test.FileName, FileMode.Create, FileAccess.Write);
formatter.Serialize(stream, wor);
} } private void button7_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "二进制文件(.bin)| *.bin";
ArrayList worklist = new ArrayList();
Worker wor = new Worker();
wor.ID = textBoxID.Text;
wor.Name = textBoxName.Text;
wor.Sex = comboBoxSex.SelectedItem.ToString();
wor.Bitrhday = dateTimePickerBirthday.Text.ToString();
wor.Constellation = (Constellations)Enum.Parse(typeof(Constellations), comboBoxConstellation.SelectedItem.ToString());
worklist.Add(wor);
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(open.FileName, FileMode.Open, FileAccess.Read);
DialogResult res=open.ShowDialog();
ArrayList loadlist = (ArrayList)formatter.Deserialize(stream);
if (res == DialogResult.OK)
{
loadlist.Add(wor);
}
}想要让一个listbox中显示序列化的内容 控件中包括导入(反序列化)导出(序列化),
谢谢各位帮忙了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货