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

Do something upon closing

I'd like to do something when a user presses the X in the top right corner. How?

I work in VB.net
Thx
Jun 18 '08 #1
3 1103
r035198x
13,262 8TB
Windows Forms application or web application?
Jun 18 '08 #2
Curtis Rutland
3,256 Expert 2GB
Windows Forms application or web application?
I'm willing to bet this is a Windows forms question.

Add an event handler for your form's FormClosing event. To do this: select the form, and in the properties window click the lightning bolt icon (events) and doubleclick the blank space to the right of FormClosing.

Make sure to take into account e.CloseReason when you do this. This is what the sub would look like.
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Form2_FormClosing(ByVal sender As System.Object,_
  2. ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  3.         If e.CloseReason = CloseReason.TaskManagerClosing_
  4.          Or e.CloseReason = CloseReason.WindowsShutDown Then
  5.             'If either of these are true, 
  6.             'you want your app to shut down immediately.
  7.             e.Cancel = False
  8.         Else
  9.             'Do what you need to do here.
  10.             MessageBox.Show("Can't Close")
  11.             'if you want the closing to be canceled, set true, else false.
  12.             e.Cancel = True
  13.         End If
  14.     End Sub
Jun 18 '08 #3
ah sorry, it's a forms indeed.

I'll try it out right now, thanx!
Jun 19 '08 #4

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

Similar topics

3
by: Alvo von Cossel I | last post by:
hi, i have a working console app. however, it closes as soon as it opens. i know that it works because i can just about read it. how do i stop it from closing straight after opening? -- Alvo...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
2
by: Henry J. | last post by:
Has anybody run into this index out range exception when opening and then closing a collectionEditor from within a PropertyGrid? I use PropertyGrid to edit configurations in my application. One...
6
by: MLH | last post by:
I get the concept of setting an object variable lilke rstCustomers to Nothing (Set rstCustomers = Nothing) But what about other variable types that can consume sizable chunks of memory. For...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.