vb.net 查找 TabPage 的索引
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19360512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find the index of a TabPage
提问by Bill Wohlers
I am using a For Each loop:
我正在使用 For Each 循环:
For Each tab As TabPage in TabControl1.TabPages
I cannot retrieve the index of tab. Is there a way to do this? I am trying to see if the index is below or above the current index.
我无法检索tab的索引。有没有办法做到这一点?我正在尝试查看该指数是低于还是高于当前指数。
回答by Jehof
回答by SteveCinq
There's also
还有
Dim indexOfTab As Integer = TabControl1.TabPages.IndexOfKey("TabName")
or
或者
Dim indexOfTab As Integer = TabControl1.TabPages.IndexOfKey(tab.Name)
This is useful if the tab page is ever removed from the collection but you want to know where it was. I know this sounds esoteric, but I've had that need quite a few times, and you can't get this information from the tab page object itself.
如果标签页曾经从集合中删除,但您想知道它在哪里,这将很有用。我知道这听起来很深奥,但我已经多次遇到这种情况,而且您无法从标签页对象本身获取此信息。

