这个问题:在可以调用OLE之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的Main函数带有STAThreadAttribute标记然后网上搜的解决方法:ThreadnewThread;privatevoidbutton1...
这个问题:
在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记
然后网上搜的解决方法:
Thread newThread;
private void button1_Click(object sender, EventArgs e)
{
newThread = new Thread(new ThreadStart(ChangePhoto));
newThread.SetApartmentState(ApartmentState.STA);
newThread.Start();
}
void ChangePhoto()
{
openFileDialog1.Filter = "图片文件|*.bmp;*.png;*.jpg;*gif";//显示所有图片文件
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
if (File.Exists(FilePath))
{
System.IO.File.Delete(FilePath);
System.IO.File.Copy(openFileDialog1.FileName, FilePath);
}
}
}
能弹出文件选择窗口了,但是执行完void ChangePhoto()函数后,窗口却自动隐藏到后端去了,又什么问题啊?求解答!谢谢
展开