VB.net hide a form instead of closing it

Murray Brown
Murray Brown used Ask the Experts™

In VB.net, what code would I use to hide a form when the user closes it? Is there a way to short circuit the closing when the user clicks the x in the top corner and instead hide it. Thanks.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Architect in .Net
Try this:

Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    If e.CloseReason = CloseReason.UserClosing Then
        e.Cancel = True
        Me.ShowInTaskbar = False
    End If
End Sub

Open in new window

Hope that helps.
Murray BrownASP.net/VBA/VSTO Developer


Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial