Remove TabPage: Dispose or Clear or both?

前端 未结 3 1282
栀梦
栀梦 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:08

    First remove a Tab from the collection, then Dispose(). Never Dispose() something that is still in use, as it will cause exceptions and strange behavior.

    Also, ensure that no one else have references to the tabs, otherwise those references will become invalid on Dispose().

提交回复
热议问题