Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Win Form.Close Handler

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Looch - 21 Sep 2007 16:24 GMT
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
Nicholas Paldino [.NET/C# MVP] - 21 Sep 2007 16:41 GMT
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.

Signature

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

> Hi All,
>
[quoted text clipped - 5 lines]
>
> Thanks in advance
Peter Duniho - 21 Sep 2007 19:36 GMT
>     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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.