Note that there are some explanatory texts on larger screens.

plurals
  1. POFormClosing with CloseReason = UserClosing doesn't work expectedly?
    primarykey
    data
    text
    <p>I have a main form, in the class of this form, I declare another form. This form lives with the main form until the main form is unloaded. There is a button on the main form, clicking this button will show the member form (I mentioned above). I want to prevent the member form from closing when user closes that form and I added the following FormClosing event handler for that form:</p> <pre><code>private void MemberForm_FormClosing(object sender, FormClosingEventArgs e) { if(e.CloseReason == CloseReason.UserClosing){ e.Cancel = true; Hide(); } } </code></pre> <p>That works OK for that form. However if user closes the main form, this form is not closed, and it's hidden somewhere making my application seem to run silently. I want this form also to be closed. This is very simple by adding some FormClosed event handler for my main form to close the member form manually. Closing it manually is OK, but why do I have to do that? It seems that when user closes the main form, the FormClosing event of the member form is fired with a parameter FormClosingEventArgs passed in and the CloseReason is the same as the CloseReason of the main form (which is UserClosing). I don't understand this, I thought the CloseReason of the form is UserClosing only when user clicks on the X button, I thought the CloseReason for my member form is something like "MainFormClosing".</p> <p>Is there some way to close the member form automatically as by default?</p> <h1>UPDATE</h1> <p>Here is the method showing the member form (showing it as a dialog):</p> <pre><code>private void ShowMemberForm_Click(object sender, EventArgs e){ memberForm.ShowDialog(); } </code></pre> <p>But I don't think this matters, because when I load my main form, even I don't need to click on the ShowMemberForm button, and try closing my main form first, it doesn't still close the member form. Thanks!</p> <h1>UPDATE</h1> <p>There is something strange here, I've tried commenting out the line <code>e.Cancel = true</code>, or even all the FormClosing event handler and the problem is still there. This is so strange, it works OK before, I've just added the member form and this form relates to some Thread handling, but the thread starts only when a button on the member form is clicked. I didn't click that button. </p>
    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.
 

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