2012-01-11 20 views
0

vb.netのWindowsアプリケーションでは、アプリケーションを閉じる前に確認する必要があります。私はFormClosingイベントユーザーがNoをクリックした場合、私は、フォームの閉鎖を解除するにはどうすればよいユーザー選択によるフォームのキャンセル

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試しましたが、機能しませんでした(アプリケーションを終了しました)。

+2

'e.Cancel = True'はフォームの終了を停止します。 – keyboardP

+0

@keyboardPありがとう..私は間違って別の言い方をしている、私のばかげて申し訳ありません... :) – Nalaka526

+0

あなたは大歓迎です! – keyboardP

答えて

3

e.Cancel = Trueを閉じてからフォームを防止します。

1

は、ドキュメントによると、「e.Cancel = True」をフォームの閉鎖を停止する

0

キャンセルフォームのフルコードです。 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 
関連する問題