473,587 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close Event ?

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 close the form.

Thks for your help

Stan
Nov 20 '05 #1
5 11061
> 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 close the form.


From the doc:

Form.Closing Event [Visual Basic]
Occurs when the form is closing.
[Visual Basic]
Public Event Closing As CancelEventHand ler

The Closing event occurs as the form is being closed. When a form is closed,
all resources created within the object are released and the form is
disposed. If you cancel this event, the form remains opened. To cancel the
closure of a form, set the Cancel property of the CancelEventArgs passed to
your event handler to true.
When a form is displayed as a modal dialog box, clicking the Close button
(the button with an X at the upper-right corner of the form) causes the form
to be hidden and the DialogResult property to be set to DialogResult.Ca ncel.
You can override the value assigned to the DialogResult property when the
user clicks the Close button by setting the DialogResult property in an
event handler for the Closing event of the form.
Note When the Close method is called on a Form displayed as a modeless
window, you cannot call the Show method to make the form visible, because
the form's resources have already been released. To hide a form and then
make it visible, use the Control.Hide method.
CAUTION The Form.Closed and Form.Closing events are not raised when the
Application.Exi t method is called to exit your application. If you have
validation code in either of these events that must be executed, you should
call the Form.Close method for each open form individually before calling
the Exit method.
If the form is an MDI parent form, the Closing events of all MDI child forms
are raised before the MDI parent form's Closing event is raised. In
addition, the Closed events of all MDI child forms are raised before the
Closed event of the MDI parent form is raised

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
*************** *************** ******
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
Nov 20 '05 #2
* "Stan Sainte-Rose" <st**@cyber972. com> scripsit:
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 close the form.


\\\
Private Sub Form1_Closing( _
ByVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs _
) Handles MyBase.Closing
If ... Then
e.Cancel = True
End If
End Sub
///

I /hate/ applications which show a messagebox before exitting...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
> I /hate/ applications which show a messagebox before exitting...

And I hate applications that close without asking to save my work _first_...

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
*************** *************** ******
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
Nov 20 '05 #4
* "Blumidoo" <no****@nottell ing.com> scripsit:
I /hate/ applications which show a messagebox before exitting...


And I hate applications that close without asking to save my work _first_...


I would at least include an option which allows the user to turn the
messagebox off.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
> > And I hate applications that close without asking to save my work
_first_...

I would at least include an option which allows the user to turn the
messagebox off.


Good point, good practice. :-)

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
*************** *************** ******
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
Nov 20 '05 #6

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

Similar topics

2
9009
by: Guy Babbitt | last post by:
I have an MDI application that starts an instance of a child form at application start. I have an event handler on a combo box checking for the selected value to change. When the select value changes, I call a method on the parent form to change some menu options, and then I need to close the child form. My code looks something like this: ...
5
7433
by: AP | last post by:
IS there a way to run a procedure if the users close access directly rather than closing a menu screen that I have built? There is an event that works on close for this form, but it doesnt seem to run if the form is open and the suer just closes access all together, is there a way around this? Thanks
3
4404
by: rdemyan via AccessMonster.com | last post by:
I need help with code to close two forms at the same time, FormA and FormB. I need code that can be used from either form and needs to work with both a 'Close' button on each form as well as if the user clicks the 'X' in the control box. I have a function, IsObjectOpen, that can be used to check if a form is open. The function is used as...
1
33121
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X", I'll need to kill the session. Now, with the onbeforeunload event, I can handle this quite easily in IE, but in FireFox, it's another matter. For one...
5
34358
by: jimmy | last post by:
Hi all, I want to capture the event when the browser's close button is clicked in an html page. I tried using the event.ClientX and event.ClientY property in the body unload event, and this helps to recognise whether the close button is clicked( also differentiates whethet refresh was clicked). The problem arises whenever i try to close...
4
6082
by: bsm | last post by:
Hi, I have googled for my issue in this group. This question was asked many times and many solution was given. But I want clear cut solution for the issue. The issue is: I tried to capture the browse close event by using Body onunload=fn1() statement and it is working fine.
2
3358
by: Bruce | last post by:
Hello, I have a form in an Access 2003 application which opens maximized. Its CloseButton property is set to false. On this form I have a command button that opens a report in preview mode. The report opens fine. It opens maximized as one would expect. However, the report preview window's close button is disabled which is confusing to...
5
5875
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and...
7
2912
by: Sin Jeong-hun | last post by:
I have a dialog form which pops up from the main window using the ShowDialog() method. this dialog has no or button, and it has quite a lot of controls on it. Now, I want to close this dialog form when the user presses the escape key, but that's only when no control on the form is responsible for the escape key. For example, it has a...
0
7915
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.