无法访问已处置的对象。 [英] Cannot access a disposed object.

查看:77
本文介绍了无法访问已处置的对象。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个菜单栏的MDIParent表单

1)注释

2)保留

当我们点击注释时它会打开注释表格

当我们点击保留菜单时,它会打开保留表格。

问题是当我第一次点击注释或保留菜单时,它会打开表格,当我再次点击打开表单关闭表单后,它会抛出异常无法访问已处置的对象。对象名称'PictureBox'..



我的两个注释和保留表单有一些动态创建的图片框。数据图片盒有什么问题吗?



m在MDI表格上使用以下代码打开我的表格..

I have a MDIParent form with two menubar
1)Annotation
2)Retention
when we click on annotation manu it will open annotation form
and when we click on retention menu it will open retention form..
the problem is when i click on annotation or retention menu for first time, it opens form, after closing form when i click again to open form it throws an exception "Cannot access a disposed object. Object Name 'PictureBox'"..

my both annotation and retention form has some dynamically created picturebox. Is there any problem with dat pictureboxes?

m using following code on MDI form to open my forms..

private void annotationToolStripMenuItem_Click(object sender, EventArgs e)
        {
Annotation frmAnnotation = new Annotation();
                frmAnnotation.Show();
            }

private void retentionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Retention frmRetention = new Retention();
        }

推荐答案

Don'看到那段代码有什么问题。你需要每次创建一个新的表单,因为它在关闭时处理,但你正在这样做。



看起来图片框的范围是错误的。你有没有把它变成静态的?
Don't see anything wrong with that code. You need to create a new form each time as it gets disposed when closed but you're doing that.

Looks like the scope of the picture box is wrong. You haven't made it a static or anything?


试试这个代码....... :)





private void toolStripMenuItem64_Click(object sender,EventArgs e)

{

try

{

Frm_DoaCreditNotePending DOADBNPartyWise = null;

if(IsFormAlreadyOpen(typeof(Frm_DoaCreditNotePending))== null)

{

DOADBNPartyWise = new Frm_DoaCreditNotePending ();

DOADBNPartyWise.Show();

DOADBNPartyWise.MdiParent = this;

}

else < br $>
{

}

}

catch {}

}





谢谢你。哈利:)
Try this code....... :)


private void toolStripMenuItem64_Click(object sender, EventArgs e)
{
try
{
Frm_DoaCreditNotePending DOADBNPartyWise = null;
if (IsFormAlreadyOpen(typeof(Frm_DoaCreditNotePending)) == null)
{
DOADBNPartyWise = new Frm_DoaCreditNotePending();
DOADBNPartyWise.Show();
DOADBNPartyWise.MdiParent = this;
}
else
{
}
}
catch { }
}


Thanks Er. Harry :)


这篇关于无法访问已处置的对象。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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