Problem in accesing mdi form

P

Pk

Hi,

Im having a problem in forms. I have a mdi parent form named Main, and
a child form named form1.
From Main form, i have a certain menu item that when clicked, it opens
form1. But the problem is that when I close form1 and I open it again
by accessing the menu, nothing happens.

When I tried to debug it, I put a breakpoint at the menu item

Private sub mnu1_click(byval sender as object, byval e system.args)
handles mnu1_click

dim frmadd as new form1
frmadd.mdiparent=me
frmadd.show()

End Sub

It generates an error, stating:

An unhandled exception of type 'System.ObjectDisposedException'
occurred in system.windows.forms.dll

Additional information: Cannot access a disposed object named "Form1".

This isnt a problem in VB6..

Thanks
 
C

Cor Ligthert [MVP]

PK,

In what form have you set this code.

Did you know that there are more experts for VB6 upgrading in the newsgroup

microsoft.public.dotnet.languages.vb.upgrading

Although this is a general question in the VB net language.
The most active newsgroup for that is

microsoft.public.dotnet.languages.vb

I hope this helps,

Cor
 
A

AMDRIT

This is working for me just fine, the only way I can imagine this occuring
for you is that frmAdd is declared at a higher scope than you are showing
here.

However, may I make a suggestion?


When you dimension a variable, you should type it first.

dim frmAdd as form1 = new form1

or, preferred

dim frmAdd as form1
frmAdd = new form1

I use a hashtable to manage special child forms. That way I know if the
form is already open and I simple BringToFront(). I handle the form's
Closed() event from my mdi parent and remove the form from from my
hashtable, remove the event handler, and manually Dispose() it

private sub muOpenSpecial_Click(Sender, e)

dim frmAdd as form1

if not myForms.Contains("FormAdd') then

frmAdd = new form1
frmAdd.mdiParent = me
addhandler frmAdd.Closed, Addressof AddForm_Closed
myForms.add("FormAdd",frmAdd)
frmAdd.show

else

frmAdd = ctype(myForms("FormAdd"),from1)
if frmadd.windowstate = minimized then
if not me.ActiveMdiChild is nothing then
frmadd.windowstate=me.ActiveMdiChild
else
frmadd.windowstate=maximized
end if
end if

end if

end sub

private sub AddForm_Closed(Sender, e)
dim frmAdd as form1
frmAdd = ctype(sender,form1)
myForms.Remove("FormAdd")
removehandler frmAdd.Closed, Addressof AddForm_Closed
frmAdd.dispose
end sub
 
P

Pk

Hi,

thanks for code
but one thing i did not get i.e myForms
and where this should be written in mdi form or child form.

Looking for quick response.
Bye
 
A

AMDRIT

myForms is the hashtable and all that code was intended to be placed in the
mdi parent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top