Better way to kill a Form after the FormClosing event is overridden to hide rather than close?
Posted
by Paul Sasik
on Stack Overflow
See other posts from Stack Overflow
or by Paul Sasik
Published on 2010-04-12T13:29:42Z
Indexed on
2010/04/12
13:33 UTC
Read the original article
Hit count: 260
I have a simple Windows Form that hosts property controls at runtime. To keep the window and its contents alive rather than killing it by handling the FormClosing event, cancel the event and simply hide the form.
That's fine but at close of the application I need to actually close the window. I implemented the below but it feels kludgey. Is there a simpler, more clever way to handle this situation? (The form's controller calls KillForm explicitly after it receives a closing event from the main window.)
Friend Class HostForm
Private _hideInsteadOfClosing As Boolean = True
Private Sub HostForm_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) _
Handles Me.FormClosing
If _hideInsteadOfClosing Then
Me.Hide()
e.Cancel = True
End If
End Sub
Public Sub KillForm()
_hideInsteadOfClosing = False
Me.Close()
End Sub
End Class
© Stack Overflow or respective owner