✔ 最佳答案
- Double click your form to bring you to the editor.
- On top of the editor, you’ll see 2 combo boxes
- On the left combo box, choose events (e.g. Form1 Events)
- On the right one, choose the ’FormClosing’ event. You can write your code here. Below is the example for asking confirmation before closing.
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As _
System.Windows.Forms.FormClosingEventArgs) Handles _
Me.FormClosing
If MessageBox.Show(’’Confirm exit?’’, ’’Exit’’, _
MessageBoxButtons.YesNo) = _
Windows.Forms.DialogResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
End Sub