|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
mdi and form disposal errorI 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? 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 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. 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? > What if the user selects the "x" close control on the task bar? That Are you using VB2005? If so, in the FormClosing event, determine if the > .close() the form correct? *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, Look into the VisibilityChanged event and clear the textboxes there either > 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? when the form is hidden or when it is shown. 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! 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
Try/Catch question
Type.GetType with two projects Threading IsNumeric Bug or misunderstanding? How to relate two objects problem with localization Simple but difficult to find solution for loading HTML into object Help referencing a variable in HTML of an aspx page SOAP with Attachments Installing a .net windows service |
|||||||||||||||||||||||