In a vb.net windows application, I need user to confirm before closing application. I have this code in FormClosing
event
If BackgroundWorker1.IsBusy Then
Dim UserSelection As Integer = MsgBox("Do you want Cancel Processing and Exit Application?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Exit Application")
If UserSelection = 6 Then
BackgroundWorker1.CancelAsync()
e.Cancel = True
Else
????
End If
End If
How can I cancel form closing if user clicked No
?
Tried e.Cancel = false
but it didn't work (exits application).
e.Cancel = True
将停止关闭表单。
根据文档“ e.Cancel = True”,可以防止表单关闭
This is full code for cancel form closed. We should use FormClosing Event.
Private Sub Frm1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show("Do you want to closed", Me.Text, MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.Cancel Then
e.Cancel = True
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.