private static string[] picAdd = new string[10];
private void button21_Click_1(object sender, EventArgs e) { Thread InvokeThread = new Thread(new ThreadStart(InvokeMethod)); InvokeThread.SetApartmentState(ApartmentState.STA); InvokeThread.Start(); InvokeThread.Join(); } private void InvokeMethod() { //定义控件数组 PictureBox[] mypic = { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10 }; if (pictureBox10.Image == null) { for (n = 0; n < 10; n++) { FormMain.ShowPic(mypic[n]); picAdd[n] = FormMain.picAddress;//传递文件的物理路径 } } else { MessageBox.Show("已经有图片,不用再添加数据!"); } } public static void ShowPic(PictureBox picBox) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files(*.*)|*.*"; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { picAddress = ofd.FileName; Image imge = Image.FromFile(picAddress); Bitmap bm = new Bitmap(imge, picBox.Width, picBox.Height); picBox.Image = bm; } }
原文地址:https://www.cnblogs.com/any-kiss/p/11610698.html
时间: 2024-10-20 09:16:33