By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,550 Members | 1,495 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,550 IT Pros & Developers. It's quick & easy.

mdi and form disposal error

P: n/a
I have a really stupid question, and cannot find the answer elsewhere.
I have a mdi that uses a class. One (main) form has two textboxes which
takes input, and the input is calculated by the class and then returned
to some labels on the same form. When I open the form from a main menu
control it works fine, if I close it using the me.close command, and
then try to reopen the form, using the same mainmenu control I recieve
an error that states: "Cannot access a disposed object named".
I've tried to instantiate a second instance of the form:

dim frm1 As New frm1
frm1.mdiparent=me
frm1.show()

however, when I do this the text boxes on the main form no longer pass
the input to the class. What is an easy fix for this?

Feb 9 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Matt,

Your message is confusing. There is no method to open a form and still you
write that you "reopen" a form.

This can that you mean show it again or instance it again. For us that is
impossible to see, so please write this kind of things clear.

However, probably will the method "form.isdisposed" help you as it mostly do
in this kind of cases.

I hope this helps,

Cor
Feb 9 '06 #2

P: n/a
CMM
Not sure I understand how you're coding this (who is maintining the
reference to the form... is it the MDIParent?). All I can say is that
frm.Close is not the opposite of frm.Show. Hide the form instead of closing
it.
Feb 9 '06 #3

P: n/a
Thanks for your time.

What if the user selects the "x" close control on the task bar? That
..close() the form correct? I attempted to go about the .hide method,
however it maintains the inputed data previously entered in the text
fields (which I don't want). Is there a way to clear all the fields
prior to showing the form after hiding it?

Feb 9 '06 #4

P: n/a
CMM
> What if the user selects the "x" close control on the task bar? That
.close() the form correct?
Are you using VB2005? If so, in the FormClosing event, determine if the
*user* is attempting to close the form, hide it instead and cancel the
close. (This is trickier in VB2003... but there are solutions).
I attempted to go about the .hide method,
however it maintains the inputed data previously entered in the text
fields (which I don't want). Is there a way to clear all the fields
prior to showing the form after hiding it?


Look into the VisibilityChanged event and clear the textboxes there either
when the form is hidden or when it is shown.

--
-C. Moya
www.cmoya.com
Feb 9 '06 #5

P: n/a
C.Moya,

Yes, I'm using 2003 version of .Net. I can remove the control box, thus
removing the "X" close. Then use the Hide event. However, I'm not sure
this is the best way to go. The VisibilityChanged Event is exactly what
I was looking for thank you!

Feb 9 '06 #6

P: n/a
CMM
Here's how to trap for "user closing" and hide the form in VB2003.
---

Private m_userClosing As Boolean = False

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Try
'WM_SYSCOMMAND / SC_CLOSE
If m.Msg = &H112 AndAlso m.WParam.ToInt32 = &HF060 Then
m_userClosing = True
End If
Catch
'do nothing
Finally
MyBase.WndProc(m)
End Try

End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

If m_userClosing Then
e.Cancel = True
m_userClosing = False
Me.Hide()
End If

End Sub
--
-C. Moya
www.cmoya.com
Feb 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.