G
Guest
I was having an issue with my forms application. In the VS 2005 IDE When the
I selected the pulldown menu File->Exit my application would close normally,
but when when I would select the 'X' in the controlbox at the top, it would
leave the application in running mode, but wouldn't return back to the IDE.
Something was hanging somewhere. I tried cleaning up any unused objects or
items in the finalize and FormClosing events, but nothing worked.
I tried the following and it seems to work for me. Add the following line
to the FormClosing event...
Global.System.Windows.Forms.Application.Exit()
The only problem I have seen with this is that it actually executes the
FormClosing event twice, so I have to make sure that anything I do in the
FormClosing block checks to make sure it wasn't already done before. I'm not
sure if I have something wrong with my project, my code, or if something is
wrong with VS 2005 and the way it does all that magical stuff in the
background when using a ControlBox. Since I don't really see a way to
override that button easily, I found this to work just fine. I thought I
would post it for others if they run into the same problem.
Just another note... When doing this research, one of the most common
threads I saw was the question "How can I override the close on the
controlbox?". That one I have found to be easy. Just override the
FormClosing event as such...
Private Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim oResult As MsgBoxResult = MsgBox("Tasks are still running in
the background. Are you sure you want to quit?", MsgBoxStyle.YesNo, "Quit all
tasks?")
If (oResult = MsgBoxResult.No) Then
e.Cancel = True
Exit Sub
End If
End Sub
I selected the pulldown menu File->Exit my application would close normally,
but when when I would select the 'X' in the controlbox at the top, it would
leave the application in running mode, but wouldn't return back to the IDE.
Something was hanging somewhere. I tried cleaning up any unused objects or
items in the finalize and FormClosing events, but nothing worked.
I tried the following and it seems to work for me. Add the following line
to the FormClosing event...
Global.System.Windows.Forms.Application.Exit()
The only problem I have seen with this is that it actually executes the
FormClosing event twice, so I have to make sure that anything I do in the
FormClosing block checks to make sure it wasn't already done before. I'm not
sure if I have something wrong with my project, my code, or if something is
wrong with VS 2005 and the way it does all that magical stuff in the
background when using a ControlBox. Since I don't really see a way to
override that button easily, I found this to work just fine. I thought I
would post it for others if they run into the same problem.
Just another note... When doing this research, one of the most common
threads I saw was the question "How can I override the close on the
controlbox?". That one I have found to be easy. Just override the
FormClosing event as such...
Private Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim oResult As MsgBoxResult = MsgBox("Tasks are still running in
the background. Are you sure you want to quit?", MsgBoxStyle.YesNo, "Quit all
tasks?")
If (oResult = MsgBoxResult.No) Then
e.Cancel = True
Exit Sub
End If
End Sub