2014-04-21 67 views
0

當某些條件得到滿足並且下面的代碼會運行很多次時,我打算做這樣的事情。如何唯一識別標籤控件?

TabPage newtabcontrol = new TabPage(); 
tabControl1.Controls.Add(newtabcontrol); 

但是我如何知道我剛添加的最新tabpage的tabIndex?

+0

控件看起來像一個集合,所以你應該能夠得到最新的標籤頁'var latestTab = tabControl1.Controls [tabControl1.Controls.Lenght-1];'。 – Leo

回答

1

您可以指定TabPage唯一的名稱

至於例如

TabPage newtabcontrol = new TabPage(); 
newtabcontrol.Name = "ID-1"; 
tabControl1.Controls.Add(newtabcontrol); 

,並找到了tabPage,您可以使用

var tabPage = tabControl1.TabPages["ID-1"] 
if (tabPage != null) 
{ 
    // perform action 
} 
0

對於這最後添加標籤頁:

TabPage newtabcontrol = new TabPage(); 
tabControl1.Controls.Add(newtabcontrol); 

TabPage temp = tabControl1.TabPages[tabControl1.TabCount - 1];