Application quit after button click

J

John Devlon

Hi ..

Can anyone please help me ?

Ik would like to raise a messagebox after the close-icon is clicked, asking
me if I'm sure to quit ...

I'm using this code ...

Private Sub myFormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

Dim intResult = MessageBox.Show("Are you sure to quit?", "Quit",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

Select Case intResult
Case intResult.Yes
frmNext.Show() 'this form handles the quit
Me.Show()
End Select
End Sub

If i click on "no", the form hides itself, but the application is still
running ... bummer....

john
 
J

John Devlon

Sorry, i forgot some line of code ...

I'm using this code ...

Private Sub myFormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

Dim intResult = MessageBox.Show("Are you sure to quit?", "Quit",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

Select Case intResult
Case intResult.Yes
frmNext.Show() 'this form handles the quit
Case inResult.No
Me.Show()
End Select
End Sub

If i click on "no", the form hides itself, but the application is still
running ... bummer....

john
 
M

marioevz

you need to use "Handles Me.FormClosing" instead of "Handles
Me.FormClosed"

John Devlon ha escrito:
 
P

Pragati Palewar

Hi John,

You need to write this code on 'Closing' event of the form instead of
writing on 'Closed' event. Here in 'closing' event you can cancel the
closing of the form just by using code of one line.

e.Cancel = True

This will cancel the closing event of the form.

Your code will look like this:

Private Sub myFormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.Closing

Dim intResult = MessageBox.Show("Are you sure to quit?", "Quit",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

if intResult = intResult.No then
e.Cancel = true 'Stops Closing of the Form
end if

End Sub

Regards,

Pragati Palewar

Palewar Techno Solutions
Windows Mobile & Palm Software Development
Nagpur, India

http://www.palewar.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top