@H_403_0@
为窗体/控件添加事件的方法:
双击窗体/控件,就会转入默认的事件,例如窗体是Load事件,按钮是Click事件,文本框是TextChanged事件……
要修改引发的事件可以采用以下方法:
@H_Private Sub Form1_FormClosing(sender As Object,e As FormClosingEventArgs) Handles Me.FormClosing Console.WriteLine("FormClosing") End Sub Private Sub Form1_FormClosed(sender As Object,e As FormClosedEventArgs) Handles Me.FormClosed Console.WriteLine("FormClosed") End Sub Private Sub Form1_Closed(sender As Object,e As EventArgs) Handles Me.Closed Console.WriteLine("Closed") End Sub Private Sub Form1_Closing(sender As Object,e As CancelEventArgs) Handles Me.Closing Console.WriteLine("Closing") End Sub@H_403_0@
Private Sub Form1_FormClosing(sender As Object,e As FormClosingEventArgs) Handles Me.FormClosing If MessageBox.Show("确定关闭窗口?","关闭",MessageBoxButtons.YesNo) = DialogResult.No Then e.Cancel = True End If End Sub点击窗体右上角的X,弹出对话框,如果选择否,那么返回窗体,如果选择是,则退出窗体。