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 / .NET Framework / Compact Framework / September 2007

Tip: Looking for answers? Try searching our database.

Catch the closing event of a form when clicked on X

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Maier - 27 Sep 2007 09:09 GMT
Hi,

I'd like to catch the click on the x of the form (that closes the form).
In a normal application I would use the Closing event and then ask for
e.CloseReason... this would tell me if I have clicked to close the form,
or if the form was closed programatically... the problem is, in the
first case I'd like the application to exit in the second I'd like to
open another form...
Can anyone help?

Thanks,
Michael
Peter Foot [MVP] - 27 Sep 2007 09:35 GMT
The way around this is to write your own method  to close the form
programmatically e.g.
private bool closedProgrammatically;
public void CloseWithFlag()
{
   closedProgrammatically = true;
   this.Close();
}

Then in  your Closing event you can check the value of this boolean flag as
you would with the built in functionality in the desktop framework.

Peter

Signature

Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility

> Hi,
>
[quoted text clipped - 8 lines]
> Thanks,
> Michael
Michael Maier - 27 Sep 2007 10:54 GMT
oh yeah.... you're right... could have thought of that by myself... :-(
I guess I have to develop this way of thinking, when it comes to CF...

Thanks a lot,
Michael

Peter Foot [MVP] schrieb:
> The way around this is to write your own method  to close the form
> programmatically e.g.
[quoted text clipped - 9 lines]
>
> Peter

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.