473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1806
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olli Piepponen | last post by:
Hi, I'm having a little problem catching keystrokes under Windows. I did a little research and found that with mscvrt.getch() one can cath a single key that is pressed. However this doesn't work...
5
by: Ron L | last post by:
I have an MDI application with a number of child windows. In each child window I am catching the Closing event and having the child window decide if it should set cancel to true. The intent here...
3
by: Elp | last post by:
Hi, I've developped a Window Form C# application which main form contains several activex controls. No problems most of the time but on some machine, the application crashes when the main form...
0
by: Nick White [MSFT] | last post by:
Hello fellow Microsoft Windows Mobile and Embedded enthusiasts: I invite you to peruse the list below of upcoming technical chats and Webcasts offered by the Windows Mobile and Embedded Devices...
2
by: Eric Sabine | last post by:
I built a generic exception handler form which allows the user to get information from it, print it, email it, etc. for exceptions for which I explicitly didn't handle in code, such as missing...
0
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
Like many people, I normally use Yahoo! Mail via the web and like to keep all my emails stored on the Yahoo! server. However sometimes I can’t get access to a PC/the web and I download my emails...
4
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
I am creating an application for windows mobile using Visual C# windows. I am using visual studio 2008 and I have windows Microsoft Vista on my computer. I also downloaded the professional and...
7
by: cj2 | last post by:
I saw a MS demo a few years back where they developed a web page and the software automatically rendered it for different devices. Is this what I'm looking for? http://www.asp.net/mobile/ ...
9
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hi, I downloaded the sample application that the Microsoft video ASPNETAJAXForWinMobile described but it doesn't work on my Windows Mobile 6 emulator. After enabling the script error reporting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.