一、打开图片
ps:必须先在pictureBox中导入一张图片
private void button4_Click(object sender, EventArgs e)//选择、更换图片 { if (openFileDialog1.ShowDialog() == DialogResult.OK)//需要工具箱的openFileDialog { Text = openFileDialog1.FileName;//选择图片 Bitmap map = (Bitmap)Image.FromFile(openFileDialog1.FileName); pictureBox1.Image = map;//更换图片 } }
二、打开txt文档
private void button5_Click(object sender, EventArgs e)//打开txt文档,仅限英文 { if (openFileDialog1.ShowDialog() == DialogResult.OK) { StreamReader sr = new StreamReader(openFileDialog1.FileName); string line; while ((line = sr.ReadLine()) != null) { listBox3.Items.Add(line); } } }