473,465 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What is the event to trap when user clicks X to close form?

On my form if the user clicks the upper right hand corner to close the form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob
Oct 21 '06 #1
6 5082
Form_Close event is fired when u try to close form.

On Sat, 21 Oct 2006 16:59:07 +0100, Robert Dufour <bd*****@sgiims.com>
wrote:
On my form if the user clicks the upper right hand corner to close the
form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob



--
Tiago Salgado // http://weblogs.pontonetpt.com/tiagosalgado
Oct 21 '06 #2
Don't forget the Form.Closing Event. Which is fired before the disposal.

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"Tiago Salgado" <ti********************@gmail.comwrote in message
news:op.thsfgaqtdysvon@tiagosalgado...
Form_Close event is fired when u try to close form.

On Sat, 21 Oct 2006 16:59:07 +0100, Robert Dufour <bd*****@sgiims.com>
wrote:
On my form if the user clicks the upper right hand corner to close the
form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob



--
Tiago Salgado // http://weblogs.pontonetpt.com/tiagosalgado
Oct 21 '06 #3
"Robert Dufour" <bd*****@sgiims.comschrieb:
On my form if the user clicks the upper right hand corner to close the
form I want to trap that event and do a check to see if closing is
allowed, if not, I want to stop the form closing action.
In addition to the other replies:

If you are using .NET 2.0, check out the form's 'FormClosing' event too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Oct 21 '06 #4
There is also the option to override the WndProc method if you really
needed to.

Thanks,

Seth Rowe
Herfried K. Wagner [MVP] wrote:
"Robert Dufour" <bd*****@sgiims.comschrieb:
On my form if the user clicks the upper right hand corner to close the
form I want to trap that event and do a check to see if closing is
allowed, if not, I want to stop the form closing action.

In addition to the other replies:

If you are using .NET 2.0, check out the form's 'FormClosing' event too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Oct 22 '06 #5
On Sat, 21 Oct 2006 11:59:07 -0400, "Robert Dufour" <bd*****@sgiims.comwrote:
>On my form if the user clicks the upper right hand corner to close the form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob
In VB6, there was the QueryUnload event which had an UnloadMode argument, one of
which was vbFormControlMenu which was specific to the "X" button and the control
menu, "Close".

In .Net, AFAIK, there is no functional equivalent short of using the WndProc method.
FormClosing event will fire when the "X" button is pressed (3-User Closing), but it
also fires for the same reason if Me.Close() is called - 3-User Closing.

Gene
Oct 22 '06 #6
Thank you all

"gene kelley" <ok**@by.mewrote in message
news:tc********************************@4ax.com...
On Sat, 21 Oct 2006 11:59:07 -0400, "Robert Dufour" <bd*****@sgiims.com>
wrote:
>>On my form if the user clicks the upper right hand corner to close the
form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob

In VB6, there was the QueryUnload event which had an UnloadMode argument,
one of
which was vbFormControlMenu which was specific to the "X" button and the
control
menu, "Close".

In .Net, AFAIK, there is no functional equivalent short of using the
WndProc method.
FormClosing event will fire when the "X" button is pressed (3-User
Closing), but it
also fires for the same reason if Me.Close() is called - 3-User Closing.

Gene

Oct 22 '06 #7

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

Similar topics

1
by: abhay | last post by:
Hello all, I want to trap the window.close() event when the user clicks on the close button of the browser using javascript. Can anyone shed light on this problem ? Thanks in advance. ...
3
by: Kelly G. | last post by:
This question is regarding the setup, Is it possible to catch the event of the close button in the installation complete windows form dialog control(finished) , I basically need to point to...
2
by: adawson | last post by:
Hi, I need to execute some code when form submission is stopped before the page is returned from the server. For example, a user clicks a button to submit the form, realizes they've made a...
5
by: Dave Hammond | last post by:
Hi All, I have a web form which performs certain actions upon moving focus away from a field. However, if the user clicks the top corner 'X' icon to close the window, the onBlur event still...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
5
by: Stan Sainte-Rose | last post by:
Hi, Which event is called when the user click on the close window icon (X) ? I want, when he clicks on this icon, to display a message before closing the form. If he replys by No, I don't want to...
3
by: Oenone | last post by:
I'm writing an application with various MDI child forms. In the Closing event of many of the forms, I have code that asks the user whether he is sure he wants to close the form, because it...
3
by: beebe | last post by:
Hi Everyone, I have created two tables. Both tables have three fields in them, one of the fields in each of the tables is a Key. The two tables have a 1-1 relationship setup with referential...
1
by: JDeats | last post by:
If you create a new C# Windows Application project in Visual Studio.NET 2003 or 2005 and proceed to. 1. Make default form size 800x600 2. Drop a CheckBoxList control and dock it to the left 3....
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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: 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.