Private Sub CloseWindow(ByVal sender As System.Object,ByVal e As System.Windows.Forms.FormClosingEventArgs) Dim closeFlag As DialogResult = DialogResult.None closeFlag = MsgBox("是否关闭窗体?",MessageBoxButtons.YesNo + MessageBoxOptions.ServiceNotification) If closeFlag = DialogResult.No Then e.Cancel = True End If End Sub
然后运行程序,发现点击窗体的关闭按钮,这个事件,并未被执行,说明这个事件和窗体的程序没有绑定在一起,添加如下操作:
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load AddHandler MyBase.FormClosing,AddressOf CloseWindow End Sub再次运行,OK,可以正常的触发事件了。 原文链接:https://www.f2er.com/vb/258431.html