Posts

Showing posts from October 20, 2019

VB.NET How to properly close a windows application Form

Image
VB.NET  How to properly close a windows application Form VB.NET How to properly close a windows application Form Requirements Visual Basic .Net (any version) , VB2010 and up recommend .NET FrameWork 4.0 and above recommended How to properly close a windows application Form in VB.NET ? You may close a Form in VB.NET Application [WinForm] by : KeyPress event Before you test this code you need to set the Form Property [KeyPreview] True, from Form Properties Window. The code below will Read Keyboard button [Escape] when clicked and Executes Close() Private Sub MainFrm_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress         If e.KeyChar = Chr(Keys.Escape) Then             Close()         End If     End Sub Then in the FormClosing() event, we will place a code to display a message [MsgBox] with [Yes, No, Cancel]. If the user clicked [Yes] then it will Close the Form and Ends the application. Private Sub MainFrm_FormClosing(sender A