"Chris" <Ch***@discussions.microsoft.comwrote in message
news:86**********************************@microsof t.com...
>I am showing a form by ShowModal(). I put a button on that form. When a
user
clicks the button a MsgBox will show with question "do you want to close?"
yes/no.
How to handle the situation:
- user clicks "yes" - the form closes
- user clicks "no" - nothing happens
I have problem with that. It seems that assigning property of
button.DialogResult wokrs ok only for the first time (in designer
generated
code and any longer)
The form itself has a FromClosing event an event just like a Button-click
event for a Button, but its for the form, which is the (lighting bolt) on
the form's Property page that shows all the events for the form. You find
the FormClosing event and you double click it to get the event established
in the code.
When the user clicks the X icon to close the form, it's going to firer the
FromClosing event where you ask the question. If the response is yes, the
closing of the form is done. If the response is no, the form closing is
cancelled and the form will not close.
Private Sub FormClosing(ByVal sender As System.Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MessageBox.Show("Are you sure to exit?", "Exit",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
End Sub