用windows窗体打开文件,用下面的代码 if (openFile.ShowDialog() == DialogResult.OK)
{
TextBox1.Text = openFile.FileName;
}但是编译的时候,说线程错误
“Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute ed on it. This exception is only raised if a debugger is attached to the process.”对线程理解不深,哪位大虾帮帮忙,多谢。
{
TextBox1.Text = openFile.FileName;
}但是编译的时候,说线程错误
“Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute ed on it. This exception is only raised if a debugger is attached to the process.”对线程理解不深,哪位大虾帮帮忙,多谢。
解决方案 »
- notifyIcon1查询到有消息,点一下跳出聊天窗体
- 请问这个sql中的update语句的执行顺序是怎样的?谢谢!
- UEditor上传图片失败
- 谁来写写看看这个C#题目(初级的)
- 统计在线人数 关闭浏览器人数不减少 知道Session过期 这个怎么处理呀
- 快速的用矩形去裁剪多边形坐标的方法
- [攒分贴]每日小知识
- 求解一个正则表达式
- 如何在线程中显示一个form?
- 【散分调查】有多少人在用DevExpress V3的控件,盗版还是正版的,全套正版价格多少?
- 在结果集dataset中怎样将指针定位到指定的记录处,又如何获取该记录在结果集中是第几条记录?
- 各位高手,高手用c#调用word的打印功能?急急~!~~~~
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using jmail;namespace WindowsApplication4
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.OpenFileDialog openFile;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.openFile = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 160);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(32, 40);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 270);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
if (openFile.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFile.FileName;
}
}
}
}
建议你重新测试(新建一个项目,只有一个form的)。
怀疑你一个项目中有两个窗体都有[STAThread]Main(){}入口了。
[AttributeUsage(AttributeTargets.Method)]
public sealed class STAThreadAttribute : Attribute
你用OpenFileDialog???
用INPUT type="file"这种应该是