Is it correct to use Dispose() to remove a Control from a Form?
E.g. I have a button 'button1' on my formular. When calling Dispose() it immediately disappears from the form and also from the 'Controls'-Collection of the form. But is this always the case? Or are there other cases (maybe other controls) where the GC waits some time?
This "bonus" of Control.Dispose
is not documented.
As a general tip, you should not build your program around expectations that undocumented behavior stays the same for the future, or even across all current control implementations.
However, as you can see from the Reference Source of Control.Dispose(bool):
if (parent != null) {
parent.Controls.Remove(this);
}
This does indeed happen in the current implementation.
But again, this is not documented behavior. Make of it what you will.