Hello,
I am trying to make a routine to handle closing a program with a confirmation dialog box.
The problem I am having is I cannot get the confirmation to work right. Here is what I have now:
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim closeprogramyes As DialogResult
Dim closeprogramno As DialogResult
closeprogramno = Windows.Forms.DialogResult.No
closeprogramyes = Windows.Forms.DialogResult.Yes
MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo)
If closeprogramyes = Windows.Forms.DialogResult.Yes Then
Me.Close()
ElseIf closeprogramyes = Windows.Forms.DialogResult.No Then
End If
End Sub
Right now if I run through that clicking yes or no closes the program. I have also tried:
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim closeprogram As DialogResult
MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo)
If closeprogram = Windows.Forms.DialogResult.Yes Then
Me.Close()
ElseIf closeprogram = Windows.Forms.DialogResult.No Then
'do nothing
End If
End Sub
If I run this nothing happens. The dialog box goes away but the program stays open. I have also tried options with e.cancel and my version of visual studio (2008) does not recognize that as a proper command.
Any help would be great as I am very new to this.
I am trying to make a routine to handle closing a program with a confirmation dialog box.
The problem I am having is I cannot get the confirmation to work right. Here is what I have now:
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim closeprogramyes As DialogResult
Dim closeprogramno As DialogResult
closeprogramno = Windows.Forms.DialogResult.No
closeprogramyes = Windows.Forms.DialogResult.Yes
MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo)
If closeprogramyes = Windows.Forms.DialogResult.Yes Then
Me.Close()
ElseIf closeprogramyes = Windows.Forms.DialogResult.No Then
End If
End Sub
Right now if I run through that clicking yes or no closes the program. I have also tried:
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim closeprogram As DialogResult
MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo)
If closeprogram = Windows.Forms.DialogResult.Yes Then
Me.Close()
ElseIf closeprogram = Windows.Forms.DialogResult.No Then
'do nothing
End If
End Sub
If I run this nothing happens. The dialog box goes away but the program stays open. I have also tried options with e.cancel and my version of visual studio (2008) does not recognize that as a proper command.
Any help would be great as I am very new to this.