473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

mdi and form disposal error

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
6 1140
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stephen Lamb | last post by:
I have a background worker thread which I start from a form's HandleCreated event that makes calls back to the form using Invoke. During shutdown the form is disposed and the background worker...
2
by: JC | last post by:
On the second pass through the obj I get this error. This is all running on my machine. I used the framework wizard to trust the interop.mydll.dll assembly, what am I missing, do I force a disposal...
7
by: Steve | last post by:
I have a method that creates of new form each time its called do i need to dipose of the form when it closes or doe the garbage collector take care of it? code private void button1_Click(object...
6
by: Robert Dufour | last post by:
On my form if the user clicks the upper right hand corner to close the form I want to trap that event and do a check to see if closing is allowed, if not, I want to stop the form closing action. ...
5
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. ...
3
Corster
by: Corster | last post by:
I'm fairly new to Access, so please have patience... I have an application that I've written to audit all of our computers, monitors etc. which also works-out the Intel processor details from the...
2
by: Mike | last post by:
Hello, Ok I have 2 classes in my project, one is the main form and one is a connection class, at a certain event on my main form a new instance is made of the connection class, and a reference...
1
by: scgamecock | last post by:
I am trying to build a search form that will display the data if the data exist and if the disposal check box is checked. I would like for an error message to display if the data exist, but the...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.