Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form closing immediately

Tags:

winforms

    Dim details As New frmDetails(ID, JobID, True)
    details.ShowDialog()

The form flashes open and immediately closes. If I use Show() rather than ShowDialog() it stays open and look fine. Here are some things I've checked:

  • Breaking in FormClosing shows only

System.Windows.Forms.Form.OnFormClosing System.Windows.Forms.Form.CheckCloseDialog System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FContinueMessageLoop System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner System.Windows.Forms.Application.ThreadContext.RunMessageLoop System.Windows.Forms.Application.RunDialog

System.Windows.Forms.Form.ShowDialog

between the ShowDialog and the FormClosing.

  • CloseReason is "None"
  • Load runs to the end, as does VisibleChanged (though Activated never gets called).
  • There's no sign of any Exceptions being thrown.
  • Intellitrace doesn't show anything going on.
  • After the form closes, the DialogResult is "Cancel" (There's no reference to DialogResult in the form or its Designer)
  • I'm not doing any explicit threading

I'd appreciate any suggestions either as to what's going on or how to go about finding out.

Thanks.

like image 359
Michael Avatar asked Nov 17 '25 14:11

Michael


1 Answers

Well, this will probably do nobody any good, but here's how I solved the problem:

There was a line in the Load method that read

Me.Text = ""

I have no idea what it was doing there (this isn't my code, thank goodness), especially since the value gets set again later on, but taking that line out stopped the form from mysteriously closing. Go figure.

like image 71
Michael Avatar answered Nov 19 '25 10:11

Michael