问题描述
我正在一个窗口的形式,有一个TabControl的命名tabDocuments上。我碰到这片code,可以消除在TabControl的所有页面。
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();
谁写了这code的人已经在不久前离开了。我试图理解为什么code为处理每一个的TabPages后调用清除()(看起来非必要我)。任何人都可以请给我解释一下为什么?或者是调用清除()额外的?
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?
推荐答案
该片段是来自Control.Dispose:
This snippet is from Control.Dispose:
if (this.parent != null)
{
this.parent.Controls.Remove(this);
}
因此,你只需要调用Dispose,尚不清楚。
Therefore you just have to call Dispose, not Clear.
这篇关于删除TabPage的:配置或清除或两者兼而有之?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!