Re: Weird Behavior in ShowDialog()

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Herfried K. Wagner [MVP] (hirf-spam-me-here_at_gmx.at)
Date: 12/16/04


Date: Thu, 16 Dec 2004 08:10:22 +0100


"Sean" <anonymous@discussions.microsoft.com> schrieb:
> I have a main window application Form A that calls
> ShowDialog() of Form B in the Click event of Form A.
>
> Sometimes when I hit the cancel button on Form B, Form B
> closes and SURPRISINGLY Form A closes as well (ie. the
> whole application exits).

Maybe assigning 'None' to the button's 'DialogResult' and adding this code
to the button's 'Click' event handler solves the problem:

\\\
Me.DialogResult = DialogResult.Cancel
Me.Close()
///

-- 
 M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
 V B   <URL:http://dotnet.mvps.org/dotnet/faqs/> 


Relevant Pages

  • Re: System.ArgumentException on close when dialog not on top
    ... showdialog confirm (dialog has a timeout after a minute if no ... I'm not trying to close the parent of a child. ... exception. ... close the parent of an active window without closing that window, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: System.ArgumentException on close when dialog not on top
    ... fires on the main UI thread already, and provided the first ShowDialog ... I'm not trying to close the parent of a child. ... exception. ... close the parent of an active window without closing that window, ...
    (microsoft.public.dotnet.framework.compactframework)
  • RE: SaveFileDialog Problem - Green Cursor
    ... >green cursor at the line where I have called the ShowDialog ... It appears your program got an unhandled exception when attempting to ... I suggest you can use the Call Stack window to locate where the exception ...
    (microsoft.public.vsnet.general)
  • Re: A doubt regarding widgets and threads.
    ... messaggio news:emVUMWKpEHA.2032@TK2MSFTNGP10.phx.gbl... ... > Why a hidden form that you pass to Application.Run on the secondary thread ... dont want that the user could interact with the main window. ... > this isn't going to work with ShowDialog. ...
    (microsoft.public.dotnet.languages.csharp)
  • How do I mimic a dialog box
    ... I want a window that acts like a dialog box, but is not a dialog box. ... Even if I skip the Dispose(), ShowDialog() seems to reset ... user from going back to the main form, while the subform is showing. ...
    (microsoft.public.dotnet.languages.csharp)