码迷,mamicode.com
首页 > 编程语言 > 详细

菜鸟解决 必须将当前线程设置为单线程单元(STA)模式的报错

时间:2019-09-30 09:32:58      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:ddr   name   设置   from   解决   控件   res   start   led   

 
  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; } }

 

菜鸟解决 必须将当前线程设置为单线程单元(STA)模式的报错

标签:ddr   name   设置   from   解决   控件   res   start   led   

原文地址:https://www.cnblogs.com/any-kiss/p/11610698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!