【发布时间】:2014-04-15 16:39:31
【问题描述】:
我有这个简单的代码:
private void buttonOpen_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = openFileDialog1.FileName;
}
}
当我运行程序时窗体不显示并退出调试模式。
在输出视图中写道:程序“[4244] openfiledialog.vshost.exe: Managed (v4.0.30319)”已退出,代码为 1073741855 (0x4000001f)。
我有 Visual Studio 2010 Professional。
编辑:form1.designer.cs
private void InitializeComponent()
{
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.buttonOpen = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// buttonOpen
//
this.buttonOpen.Location = new System.Drawing.Point(13, 48);
this.buttonOpen.Name = "buttonOpen";
this.buttonOpen.Size = new System.Drawing.Size(75, 23);
this.buttonOpen.TabIndex = 0;
this.buttonOpen.Text = "open";
this.buttonOpen.UseVisualStyleBackColor = true;
this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(113, 50);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(279, 20);
this.textBox1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(13, 98);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(385, 20);
this.textBox2.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(445, 216);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.buttonOpen);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
【问题讨论】:
-
你在哪里声明你的 openFileDialog?
-
关于openfiledialog的好教程c-sharpcorner.com/uploadfile/mahesh/openfiledialog-in-C-Sharp
-
你需要发布更多的代码,以及更多关于正在发生的事情的细节。表格是否显示?你点击按钮了吗?
-
我在设计中声明(在工具箱中我拖放)。当我单击运行调试时,它显示表单,但是当我单击按钮时,表单关闭并退出调试模式。
-
查看退出代码发现了这个:stackoverflow.com/questions/4532457/…。程序中的其他内容可能导致调试器退出。由于您只发布了事件处理程序,因此无法判断。
标签: c# winforms visual-studio-2010 openfiledialog