Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As per <a href="http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx" rel="nofollow noreferrer">MSDN</a>, Modal forms invoked via <code>ShowDialog()</code> are not disposed automatically and the onus is on the developer to dispose them:</p> <blockquote> <p>When a form is displayed as a modal dialog box, clicking the Close button (the button with an X at the upper-right corner of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel. Unlike modeless forms, the Close method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog box. Because a form displayed as a dialog box is not closed, you must call the Dispose method of the form when the form is no longer needed by your application.</p> </blockquote> <p>The relevant point here is "when the form is no longer needed". In your case, you seem to need the form for subsequent actions, therefore wrapping the <code>ShowDialog()</code> call in a <code>using</code> construct would not serve the purpose.</p> <p>My suggestion would be to dispose of the Dialog in the Dispose method of your Main form, or as early as possible:</p> <pre><code>protected override void Dispose(bool disposing) { if (disposing &amp;&amp; (components != null)) { components.Dispose(); } // dlg is a variable of type Form2(the dialog) if (dlg != null) { dlg.Dispose(); dlg = null; } base.Dispose(disposing); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload