Where should I manage the subtitle

I have a FormA that creates another FormB when a button is clicked.

Where should I handle FormB. Can I handle FormB in a FormA close event?

+4
source share
4 answers

When FormB is closed (using the .Close method), it will be deleted, so you do not need to manually call the .Dispose method.

+6
source

When FormB closes by clicking on X or other features where it is simply hidden, it is not deleted. If this form is common in this case, delete it when you exit FormA or the application. If this form is not open, you can often use it in a click-event event handler. There you can use the using keyword.

 using(FormB b = new FormB()) { if(b.ShowDialog() == DialogResult.OK) {...} else {...} } 

Of course, this is possible only when it is shown modal.

0
source
  protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } 

you can see it in the form designer.cs file, it will be called when the form is closed, so you do not need to worry about recycling

0
source

from msdn

Two conditions when the form is not located at the close, when (1) it is part of the multi-document interface (MDI), and the form is not visible; and (2) you displayed the form using ShowDialog. In these cases, you need to call Dispose manually to mark all forms of garbage collection.

Better to use with:

 using (var modalForm = new FormB()) { modalAddUser.ShowDialog(); } 
0
source

All Articles