469,910 Members | 1,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,910 developers. It's quick & easy.

Catching the _closing event on Windows Mobile 5.0

Hello Everyone,

I am writing a Windows Mobile 5.0 application using VS 2..8 in VB.NET.
When someone clicks the "Exit" menu option, which generates a
button_click() event, I find it easy to display an "Are you sure?"
MessgeBox before the application closes. That way, if they
accidentally selected exit, they have a chance to back out. But I also
want to catch the _closing() event on the form in case the user clicks
the application close X on the top of the application. When I use the
following code, it doesn't do anything at all:

Private Sub MainForm_Closing(ByVal sender As System.Object, ByVal e
As _
System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing

Dim rs As Integer

rs = MessageBox.Show("Are you sure you want to exit?",
"Confirm Exit", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
If (rs = vbOK) Then
Application.Exit()
Else
Return
End If
End Sub

Am I doing this wrong? How can I best deal with this event? Is it even
possible?

Thanks!
Anthony
Jun 27 '08 #1
3 1691
On Apr 22, 6:50 am, "Anthony P." <papill...@gmail.comwrote:
Hello Everyone,

I am writing a Windows Mobile 5.0 application using VS 2..8 in VB.NET.
When someone clicks the "Exit" menu option, which generates a
button_click() event, I find it easy to display an "Are you sure?"
MessgeBox before the application closes. That way, if they
accidentally selected exit, they have a chance to back out. But I also
want to catch the _closing() event on the form in case the user clicks
the application close X on the top of the application. When I use the
following code, it doesn't do anything at all:

Private Sub MainForm_Closing(ByVal sender As System.Object, ByVal e
As _
System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing

Dim rs As Integer

rs = MessageBox.Show("Are you sure you want to exit?",
"Confirm Exit", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
If (rs = vbOK) Then
Application.Exit()
Else
Return
End If
End Sub

Am I doing this wrong? How can I best deal with this event? Is it even
possible?

Thanks!
Anthony
Hi Anthony,

I hope that works for you and fixes your problem:

Private Sub MainForm_Closing(ByVal sender As System.Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

Dim rs As Integer

' Define MsgBox
rs = MessageBox.Show("Are you sure you want to exit?", "Confirm Exit",
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)

' Exit if OK is clicked
If rs = vbOK Then
Application.Exit()

' Else stay awake
Else
e.Cancel = True

End If

End Sub
Hope this helps,

Onur Güzel

Jun 27 '08 #2
Thank you Onur!
I'm not sure if it worked for me or not because I'm not at my dev
machine but I can already see some changes I need to make. Thanks for
your input!

Anthony
Jun 27 '08 #3
On Apr 23, 12:28*am, "Anthony P." <papill...@gmail.comwrote:
Thank you Onur!
I'm not sure if it worked for me or not because I'm not at my dev
machine but I can already see some changes I need to make. Thanks for
your input!

Anthony
Anthony, i tested it on my machine and worked, i hope the same effect
for you :-)

Let us know,

Regards,

Onur Güzel
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Olli Piepponen | last post: by
5 posts views Thread by Ron L | last post: by
3 posts views Thread by Elp | last post: by
reply views Thread by Nick White [MSFT] | last post: by
2 posts views Thread by Eric Sabine | last post: by
reply views Thread by =?Utf-8?B?Q2hhcmxlcw==?= | last post: by
4 posts views Thread by =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post: by
7 posts views Thread by cj2 | last post: by
9 posts views Thread by =?Utf-8?B?RGFuaWVs?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.