Remove TabPage: Dispose or Clear or both?

前端 未结 3 1289
栀梦
栀梦 2021-01-19 16:33

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 (in         


        
3条回答
  •  感情败类
    2021-01-19 17:12

    Calling Dispose() on each of the tab pages does not actually remove them from the TabPages collection, it simply disposes them. The call to Clear() is what removes them from the collection. If you don't call Clear() they will still be there, and bad things will likely happen because you will end up trying to use them after they have been disposed.

提交回复
热议问题