When writing a windows form using Visual Basic 2005 Express?
i would like to display a message box when a user clicks on the 'X' button on the top right hand corner of the screen.
Is there also another way to cancel the 'X' button but still keep the minimize button?
NOTE: The use of the e variable which is used to determine why the form is closing. You only want to prompt for confirmation if the user is clicking the X. If the system is closing the program form due to a shutdown or any other reason you want to allow the form to close with out prompting.
Private Sub frmRHdemo_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'Confirm Form Close
Dim ans As DialogResult
If e.CloseReason = CloseReason.UserClosing Then
'Only prompt if User is attempting to close the form
'otherwise allow the system to close form unimpeaded
'
ans = MessageBox.Show("Do you wish to Exit?", _
"Form Closing:", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question)
'
If ans = Windows.Forms.DialogResult.No Then e.Cancel = True
End If