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

How to handle close window event?

Hi all,
Can anyone tell me which event get generated when I close window
(e.g. of Form1) by cliking on its close button 'X' on rt handside on top of window.
I need to execute perticular code when I close the window.
Feb 9 '07 #1
4 4547
iburyak
1,017 Expert 512MB
Put your code in Form_QueryUnload event.
Feb 9 '07 #2
Killer42
8,435 Expert 8TB
Put your code in Form_QueryUnload event.
Yes, use the QueryUnload event if you want to have the option of cancelling (stopping) the unload. You can also place code in the Unload event (which fires after QueryUnload), but at that point you don't have the option to cancel the close.

One nice thing about QueryUnload is that you receive a parameter telling you how/why the close was requested. So you can react differently depending on whether the user closed the form, or your code did it, or Windows is shutting down.
Feb 10 '07 #3
hariharanmca
1,977 1GB
Yes, use the QueryUnload event if you want to have the option of cancelling (stopping) the unload. You can also place code in the Unload event (which fires after QueryUnload), but at that point you don't have the option to cancel the close.

One nice thing about QueryUnload is that you receive a parameter telling you how/why the close was requested. So you can react differently depending on whether the user closed the form, or your code did it, or Windows is shutting down.

We can use Form_Unload to cancel colseing form

Expand|Select|Wrap|Line Numbers
  1. dim boolClose  as Boolean
  2.  
  3. Private Sub Form_Unload(Cancel As Integer)
  4.     If boolClose = True Then
  5.         Cancel = 0
  6.         cmdClose_Click
  7.     Else
  8.         Cancel = 1
  9.     End If
  10. End Sub
Feb 10 '07 #4
Killer42
8,435 Expert 8TB
We can use Form_Unload to cancel closing form...
Sorry, my goof. Both events do have the Cancel option. I must have been getting confused with UnloadMode, which is only available in QueryUnload.
Feb 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
7
by: lkr | last post by:
hi is there is anyway to capture the document events of a MSWord?eg:I have to handle the event awhen WM_KEYUP or anyother events will occur. give me a solution............ thanks in advance lkr
12
by: Daniel Walzenbach | last post by:
Hi, I have a Website which allows users to input data. After they finished entering data they can click a button to save their input. Problem now is, that I have no possibility to visualize that...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
0
by: Vam$y | last post by:
In asp.net how to catch window close event when a user closes the window explicitly by clicking on “x” button which is on the right top corner of the browser. My requirement is When a user...
13
by: Abhishek | last post by:
Hi, how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application only even if there is any other window in front of it. I dont...
2
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some...
5
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.