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 / Windows Forms / WinForm General / April 2006

Tip: Looking for answers? Try searching our database.

ClosingEventArgs 'Cancel' member already set to true by framework

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RitualDave - 04 Apr 2006 18:30 GMT
I'm having a difficult time trying to track this issue down.  Hopefully,
someone might be able to share some insight.

I have a situation where a form is not closed when I explicitly call Close()
on it.  As part of trying to debug this problem, I overrode the "OnClosing"
method (and OnFormClosing, too) and noticed that the 'Cancel' member of the
ClosingEventArgs parameter is already set to true upon entering and before I
explicitly forward the call to base.OnClosing(). If I force Cancel to be
false, then the form will close without a problem.

Does anyone have an idea why the framework is setting Cancel to true?

It is difficult to reproduce the problem with a small example.  What I can
tell you is that the form in question is a TopLevel (and TopMost) form with
the Owner property set to an MDI child.  The TopLevel form has a splitter
control that houses two child forms... however, I remove the splitter control
from the form before I call Close() (the form then contains no child
controls).  This is the point where the form fails to close.
Dmytro Lapshyn [MVP] - 05 Apr 2006 07:30 GMT
Hi RitualDave!

If we are lucky, this is a known issue with Windows Forms when a control
that owns the focus is being removed dynamically.

See the link below for suggested resolution:

http://www.pcreview.co.uk/forums/showpost.php?s=63c7c13afc2c8573f183c5b9d19fcce8
&p=3926586&postcount=2


The crucial point is to call OnControlRemove on the parent before removing a
child control.

> I'm having a difficult time trying to track this issue down.  Hopefully,
> someone might be able to share some insight.
[quoted text clipped - 20 lines]
> from the form before I call Close() (the form then contains no child
> controls).  This is the point where the form fails to close.
RitualDave - 05 Apr 2006 17:55 GMT
Excellent.  Thanks, Dmytro!

> Hi RitualDave!
>
[quoted text clipped - 32 lines]
> > from the form before I call Close() (the form then contains no child
> > controls).  This is the point where the form fails to close.

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.