浏览按钮编码错误 [英] Browse button coding error

查看:117
本文介绍了浏览按钮编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我将以下代码用于浏览按钮"时.

Hi,

When i''m using the below code for Browse Button.

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    textBox1.Text = openFileDialog1.FileName;
}



我收到以下错误:



I''m getting the below error:

Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process

.

推荐答案

在Main方法上添加STAThreadAttribute属性.

http://msdn2.microsoft.com/en-us/library/system .stathreadattribute(vs.71).aspx [
Add the STAThreadAttribute attribute on the Main method.

http://msdn2.microsoft.com/en-us/library/system.stathreadattribute(vs.71).aspx[^]

For example,

[STAThread]
static void Main(string[] args)
{
    // rest of the code goes here
}


我使用以下代码解决了自己:
私有void btnBrowseFile_Click(对象发送者,EventArgs e)
{
openFileDialog1.ShowDialog();
}
I solved myself by using the below code:
private void btnBrowseFile_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}


这篇关于浏览按钮编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆