473,324 Members | 2,511 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,324 software developers and data experts.

Form Closing event

I need to display a confirmation message box when the user tries to exit the
main form of my application. I placed code in the MainForm_Closing event to
handle this and it works as expected. Now I show a modal LoginForm in
MainForm_Load using ShowDialog(). If the user clicks cancel on the
LoginForm then I want to close the MainForm, but I don't want to ask the
user if he wants to exit. What is the best way to do this? Is there some
way of detecting what originated the Closing event? I only want to display
the message box if the user clicked the "X" and not if I call
MainForm.Close. I hope this makes sense.
Nov 17 '05 #1
1 2534
Trevor,

Instead of bringing up the new form in the load event of the form main
form, I would run two application loops (calls to the static Run method on
the Application class). The first would be for your login form. If the
login succeeded, then I would then show your main form (if not, you would
exit your program).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Trevor" <tr****@spam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to display a confirmation message box when the user tries to exit
the main form of my application. I placed code in the MainForm_Closing
event to handle this and it works as expected. Now I show a modal LoginForm
in MainForm_Load using ShowDialog(). If the user clicks cancel on the
LoginForm then I want to close the MainForm, but I don't want to ask the
user if he wants to exit. What is the best way to do this? Is there some
way of detecting what originated the Closing event? I only want to display
the message box if the user clicked the "X" and not if I call
MainForm.Close. I hope this makes sense.

Nov 17 '05 #2

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

Similar topics

5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
2
by: Nenad Dobrilovic | last post by:
Hi, is there any way to find out how form was closed (by calling it's method Close() or by clicking on the 'close' button in control box)? Also, can I close the form in that way that Cloing/Closed...
1
by: Jon Pope | last post by:
I've got an MDI Parent which hosts several child forms. When the application closes (either through a File|Exit call or by clicking on the "X" in the upper right corner), I check to see if any of...
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
5
by: Ivan | last post by:
I am used to VB6 and am not sure how to do this in Vstudio .NET. I have a main form which calls other forms. I want to disable that main form while other ones are called. I tried hiding it and...
5
by: Oenone | last post by:
I have a VB.NET form which I'm displaying modally using the ShowDialog() method. Within the form is a Cancel button, and I've set this button into the Form's CancelButton property so that...
6
by: **Developer** | last post by:
I've been looking but can't find out how in a form Closing event to know if the closing is because the form's "X" had been clicked or the main form's "X" was clicked. That is, I need to know if...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
19
by: zacks | last post by:
I have a .NET 2.0 MDI application where the child form has a Tab Control. Each of the Tab in the Tab Control has a Validating event to handle what it should do when the user changes tabs. But...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.