Jeff576878

I'm using VB.NET 2005 express edition with the 2.0.50727 framework.

I have a MDI application that works great except for the mysterious closing of all of the Child Forms when every I try to open a dialog box or switch to another running app. Setting a breakpoint in the FormClosed subroutine of the child showed that the child form was the sender and that the e.CloseReason was user closing.

I realize that I can check the e.CloseReason and cancel the closing of the form in the FormClosing subroutine, but I wouldn't be able to close the form except by closing the application as far as I can tell.

Am I missing something here

Thanks,

Jeff



Re: Visual Basic Language MDI Child closes when a file dialog is opened and other unexpected times

CommonGenius.com

Handle the FormClosing event, set a breakpoint in it, and post the stack trace (from the call stack window). Make sure you uncheck Hide Non-User Code (right-click in the call stack window).




Re: Visual Basic Language MDI Child closes when a file dialog is opened and other unexpected times

Jeff

Here it is:

> EngineeringDB.exe!EngineeringDB.frmMachines.frmMachines_FormClosing(Object sender = {EngineeringDB.frmMachines}, System.Windows.Forms.FormClosingEventArgs e = {System.Windows.Forms.FormClosingEventArgs}) Line 14 Basic
System.Windows.Forms.dll!System.Windows.Forms.Form.OnFormClosing(System.Windows.Forms.FormClosingEventArgs e) + 0x62 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.WmClose(ref System.Windows.Forms.Message m = {msg=0x10 (WM_CLOSE) hwnd=0x7086e wparam=0x0 lparam=0x0 result=0x0}) + 0xb6 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) + 0x16d bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0xd6 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 16, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Control.SendMessage(int msg, int wparam, int lparam) + 0x3d bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.Close() + 0x61 bytes
EngineeringDB.exe!EngineeringDB.frmMain.frmMain_Deactivate(Object sender = {EngineeringDB.frmMain}, System.EventArgs e = {System.EventArgs}) Line 79 + 0xa bytes Basic
System.Windows.Forms.dll!System.Windows.Forms.Form.OnDeactivate(System.EventArgs e) + 0x62 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.Active.set(bool value) + 0x189 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.WmActivate(ref System.Windows.Forms.Message m) + 0x37 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) + 0x13e bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0xd6 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 6, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x1c3 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.WinFormsAppContext}) + 0x17d bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context) + 0x15 bytes
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() + 0xc0 bytes
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() + 0xe4 bytes
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(string[] commandLine) + 0x62 bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x32 bytes
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes

Did I get everything you needed

Thanks,

Jeff





Re: Visual Basic Language MDI Child closes when a file dialog is opened and other unexpected times

Jeff

Thank you, I see what is happening now.

In my main form's deactivate event there is some code that is closing the child windows.

Thanks again,

Jeff





Re: Visual Basic Language MDI Child closes when a file dialog is opened and other unexpected times

CommonGenius.com

Glad you solved the problem. Don't forget to mark at least one post as an answer, even if its your own.




Re: Visual Basic Language MDI Child closes when a file dialog is opened and other unexpected times

Jeff

When I saw the following line in the Call Stack Window it all became clear:

EngineeringDB.exe!EngineeringDB.frmMain.frmMain_Deactivate(Object sender = {EngineeringDB.frmMain}, System.EventArgs e = {System.EventArgs}) Line 79 + 0xa bytes Basic

I had some code that closed all Child forms when the Parent form was closed, however I placed it in the frmMain_Deactivate rather than in frmMain_Closing.

Jeff





Re: Visual Basic Language MDI Child closes when a file dialog is opened and other unexpected times

CommonGenius.com

And the moral of the story is: stack trace is your best friend when debugging Smile

I would like to point out, though, that when the MDI parent form closes, it will automatically close the MDI children; you shouldn't need to close them explicitly.