private void button3_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox4.Text = openFileDialog1.FileName;
}
}
private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
listBox2.Items.Clear();
listBox2.Items.Add("no\tname\tsex");
Stream stream = openFileDialog1.OpenFile();
BinaryFormatter bf = new BinaryFormatter();
StudentList students = (StudentList)bf.Deserialize(stream);
int k = 0;
while (students[k] != null)
{
int s_no = students[k].sno;
string name = students[k].name;
bool isMale = students[k].sex;
string sex = "";
if (isMale)
sex = "man";
else sex = "woman";
string result = string.Format("{0}\t{1}\t{2}", s_no, name, sex);
listBox2.Items.Add(result); k++;
}
stream.Close();
}
【水汐のC#】 3. 按操作完成【例11-5】, 在【11-3】和[11-4】的基础上通过OpenFileDialog控件实现打开文件功能
最新推荐文章于 2024-04-07 15:10:09 发布