Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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..
MSIL
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();
        }
Posted
Updated 17-Feb-17 21:54pm

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?
 
Share this answer
 
Comments
Legendof507 17-Feb-11 4:48am    
i created picturebox like dis..
static public PictureBox _imgedt = new PictureBox();
Rob Philpott 17-Feb-11 4:55am    
That's the problem then. Remove that static keyword and instantiate the picturebox in your form constructor.
Manfred Rudolf Bihy 17-Feb-11 4:58am    
Good answer! 5+
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 :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900