c#重新打开子窗体出现无法访问已释放对象的异常

版权声明:本文为博主原创文章,转载请发邮件到844804539@qq.com授权。 https://blog.csdn.net/qq_33712555/article/details/78775346

解决方法:
private void mdiFormClosing(object sender, FormClosingEventArgs e)
{
Form mdiForm = (Form)sender;
mdiForm.Hide();//隐藏被关闭的窗体
e.Cancel = true;//撤销窗体关闭操作
}

无法访问释放对象!!!!!

10-16

以下是form1的代码:rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnrnnamespace _20080517S2rnrn public partial class MainForm : Formrn rn From2 fa;rn public MainForm()rn rn InitializeComponent();rn fa = new From2();rn fa.MdiParent = this;rn fa.WindowState = FormWindowState.Maximized;rn fa.button1.Click += new EventHandler(button1_Click);rn rn rn rn void button1_Click(object sender, EventArgs e)rn rn MessageBox.Show(fa.Timu);rn fa.Close();rn rn rn rn rn private void 增加题目ToolStripMenuItem_Click(object sender, EventArgs e)rn rn fa.Show();rn rn rnrnrnrn下面是form2的代码:rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnrnnamespace _20080517S2rnrn public partial class From2: Formrn rn public From2()rn rn InitializeComponent();rn rn public string Timurn rn get return this.textBox1.Text; rn rn public string XX1rn rn get return this.textBox2.Text; rn rn public string XX2 rn get return this.textBox3.Text; rn rn public string XX3 rn get return this.textBox4.Text; rn rn public string XX4 rn get return this.textBox5.Text; rn rnrn private void button1_Click(object sender, EventArgs e)rn rn MessageBox.Show(this.Timu);rn rn rn rnrnrnrn第一次点击”增加题目“时 form2 正常SHOW出来!rnrn输入完后 点FORM2的Button1关闭rnrn然后第二次点击“增加题目”的时候就会出现 “无法访问已释放的对象” 的错误rnrn为什么会这样 rnrn环境:VS2008 论坛

没有更多推荐了,返回首页