Vb.net 按用户选择取消表单关闭
在vb.net windows应用程序中,我需要用户在关闭应用程序之前进行确认。我在Vb.net 按用户选择取消表单关闭,vb.net,Vb.net,在vb.net windows应用程序中,我需要用户在关闭应用程序之前进行确认。我在FormClosing事件中有此代码 If BackgroundWorker1.IsBusy Then Dim UserSelection As Integer = MsgBox("Do you want Cancel Processing and Exit Application?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Exit Applicat
FormClosing
事件中有此代码
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
如果用户单击了否
,如何取消表单关闭
尝试了
e.Cancel=false
,但它不起作用(退出应用程序)。根据文档“e.Cancel=True”阻止表单关闭根据文档“e.Cancel=True”阻止表单关闭e.Cancel=True
将停止表单关闭 e.Cancel=True
将停止表单关闭 这是取消表单关闭的完整代码。我们应该使用FormClosing事件
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
这是取消表单关闭的完整代码。我们应该使用FormClosing事件
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
e.Cancel=True
将停止表单关闭。@键盘P谢谢。。我错误地换了一种说法,很抱歉我的愚蠢…:)@keyboardP把你以前的评论作为答案,我会接受的。e.Cancel=True停止表单关闭e.Cancel=True
将停止表单关闭。@keyboardP谢谢。。我错误地换了个说法,对不起我的愚蠢…:)@keyboardP把你之前的评论作为答案,我会接受的。e.Cancel=True stop form closing