Home All Groups Group Topic Archive Search About

Application quit after button click

Author
31 Aug 2006 8:14 PM
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

Author
31 Aug 2006 8:17 PM
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
Author
31 Aug 2006 9:55 PM
marioevz@gmail.com
you need to use "Handles Me.FormClosing" instead of "Handles
Me.FormClosed"

John Devlon ha escrito:

Show quoteHide quote
> 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
Author
1 Sep 2006 7:57 AM
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