473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Confirm Exit in a Mdi form?

Hallo,

I have a Mdi form in which I show a MessageBox if the user tries to
close it. If the user clicks YES, then the form closes; if it clicks
NO then it aborts.

I added the following lines in my form Closing event:

If MessageBox.Show("Are you sure do you want to exit?", gsAppName,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If

But it doesn't work. So I was wondering if someone is so kind to point
me to the error.

I'm using VB.NET

Thanks in advance.

PS My apologies for my bad english.

Best Regards,
David Desmet
Jun 27 '08 #1
4 3040
On Jun 11, 12:23 pm, iDesmet <idesmet.w...@gmail.comwrote:
Hallo,

I have a Mdi form in which I show a MessageBox if the user tries to
close it. If the user clicks YES, then the form closes; if it clicks
NO then it aborts.

I added the following lines in my form Closing event:

If MessageBox.Show("Are you sure do you want to exit?", gsAppName,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If

But it doesn't work. So I was wondering if someone is so kind to point
me to the error.

I'm using VB.NET

Thanks in advance.

PS My apologies for my bad english.

Best Regards,
David Desmet
David,
Try this one:

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

If MessageBox.Show("Are you sure do you want to exit?",
"gsAppName",MessageBoxButtons.YesNo,
MessageBoxIcon.Question,MessageBoxDefaultButton.Bu tton2) =
Windows.Forms.DialogResult.Yes Then
Application.Exit()
Else
e.Cancel = True
End If
End Sub

Thanks,

Onur Güzel
Jun 27 '08 #2
"iDesmet" <id**********@gmail.comschrieb
Hallo,

I have a Mdi form in which I show a MessageBox if the user tries to
close it. If the user clicks YES, then the form closes; if it clicks
NO then it aborts.

I added the following lines in my form Closing event:

If MessageBox.Show("Are you sure do you want to exit?", gsAppName,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes
Then Me.Close()
End If

But it doesn't work. So I was wondering if someone is so kind to
point me to the error.

If MessageBox.Show("Are you sure do you want to exit?", gsAppName, _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.No
Then
e.cancel = True
End If

Note: DialogResult.Yes changed to DialogResult.No.

You don't have to (or must not) call Me.Close because it must have been
called before already; otherwise the FormClosing event would not have been
fired.
Armin

Jun 27 '08 #3
David,

Just from my memory.

DirectCast(me.MDIParent,TheMainForm).Close()

Would do the trick

(I am not so busy with all the kind of tricks in VBNet for VB6 users, so
maybe it can be done with less code)

Cor

"iDesmet" <id**********@gmail.comschreef in bericht
news:17**********************************@d45g2000 hsc.googlegroups.com...
Hallo,

I have a Mdi form in which I show a MessageBox if the user tries to
close it. If the user clicks YES, then the form closes; if it clicks
NO then it aborts.

I added the following lines in my form Closing event:

If MessageBox.Show("Are you sure do you want to exit?", gsAppName,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If

But it doesn't work. So I was wondering if someone is so kind to point
me to the error.

I'm using VB.NET

Thanks in advance.

PS My apologies for my bad english.

Best Regards,
David Desmet

Jun 27 '08 #4
Thank you all for the kind help and fast reply... this has helped me
very much.

I appreciate your time.

Thanks,
David Desmet
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: T.E. | last post by:
Hi all, I'm a newbie in php. I encounter a problem with php form that has only one textfield. If I click on the submit button, the form works fine. However, when I press 'enter', the form...
1
by: Robert V | last post by:
Hi all, I could use some help programming on of my Perl script to handle different submit buttons within the same form. Here is what I have so far. A user goes to a Web form and inputs some data...
4
by: btopenworld | last post by:
I am submitting a form using an image as the link to a js file. The image calls a js function which checks fields- issuing alerts for errors - if no errors it then submits the form. I would like...
2
by: Laurent Bertin | last post by:
Hi i got a strange problem but it's true i don't make thing like anyone... First Config: + IIS5.0 SP2 (yes i know...) WebSite Security Root : Digest Authentication, NT Authenticated SubFolders...
2
by: Raed Sawalha | last post by:
i have form i need when user Close the form a messagebox confirm him with Yes or No if yes exist if no stay....how can i achieve this?
3
by: Simon | last post by:
I need to force a exit if a critical file is not found???
13
by: deko | last post by:
I have a basic feedback form with a submit button. After the "send" button is clicked, I want the user to be redirected to a different page that says "Your message has been sent." How do I do...
3
by: RLN | last post by:
Re: Access 2003 I have a process that sends out emails to addresses (internally in our company). Form1 has all the main functionality/data, etc on it. When the user clicks "Send Emails" on...
5
by: John Boyd | last post by:
I know I can post to page 2 but the problem is I need to capture the name, email (optional), and referral source. If i post to page 2 then it simply asks for the required fields. If I do get it...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.