I am working on a windows form that has a TabControl named tabDocuments. I came across this piece of code that removes all pages from the TabControl.
for (int i = tabDocuments.TabPages.Count - 1; i > -1; i--) {
tabDocuments.TabPages[i].Dispose();
}
tabDocuments.TabPages.Clear();
The person who wrote this code has already left a while ago. I am trying to understand why the code is calling Clear() after disposing each of the tabPages (looks un-necessary to me). Can anyone please explain to me why? Or is calling Clear() extra?
This snippet is from Control.Dispose:
if (this.parent != null)
{
this.parent.Controls.Remove(this);
}
Therefore you just have to call Dispose, not Clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With