Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 按用户选择取消表单关闭_Vb.net - Fatal编程技术网

Vb.net 按用户选择取消表单关闭

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

在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 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