473,387 Members | 3,821 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,387 software developers and data experts.

Win Form.Close Handler

Hi All,

How can I add a handler to the closing of a windows form if the user
selects the 'X' in the upper right hand corner of a form? Basically
I'd like to make sure that certain text boxes are filled in before the
form can be closed. I haven't had the need for handlers untill now so
I'm definately new at this!

Thanks in advance

Sep 21 '07 #1
2 4398
Looch,

Have you taken a look at the Closing event on the Form class? If the
form isn't filled out the way you need it to be, you can cancel the
operation.

Also, you might want to look at the Validating event as well.

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

"Looch" <lu**********@yahoo.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
Hi All,

How can I add a handler to the closing of a windows form if the user
selects the 'X' in the upper right hand corner of a form? Basically
I'd like to make sure that certain text boxes are filled in before the
form can be closed. I haven't had the need for handlers untill now so
I'm definately new at this!

Thanks in advance

Sep 21 '07 #2
Nicholas Paldino [.NET/C# MVP] wrote:
Have you taken a look at the Closing event on the Form class? If the
form isn't filled out the way you need it to be, you can cancel the
operation.
As of .NET 2.0 (I believe), the FormClosing event is the preferred event
to use.
Also, you might want to look at the Validating event as well.
Agreed. Each control can raise a Validating event, and the handler for
that event can indicate the control isn't valid, preventing the form
from closing.

Pete
Sep 21 '07 #3

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
5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
0
by: Giri | last post by:
Hi there..You cannot close a form in Load. You can set a flag and close it in Activate Event of Form Warm regards, Giri >-----Original Message----- >I need to be able to close the form (or...
13
by: Lorne Smith | last post by:
Hi, First, sorry for the crosspost, but it seemed appropriate... :) I've come accross what I consider to be a bug, but I don't know if it's already known or not. (VS .Net 2003 Pro - VB.Net) ...
5
by: Scott H | last post by:
Hi All, Coming from VB6, there was a bit of a difference in the way you display a form, I Thought I'd nailed instanciating a form, but I'm quite stuck with something that doesn't make sense. ...
7
by: Boni | last post by:
Dear all, if I do myform.close() is it disposed or not? is it correct do following? myForm.close() Info=SomeControlOntheForm.text This seems to work. But am not sure that it is waterproof....
4
by: polocar | last post by:
Hi, I would like to find a way in C# so that, when the user presses the "Esc" key, the form closes; the problem is that I have a lot of controls in the form. At the beginning I have tried with...
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...
7
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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?
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
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...

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.