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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:28:22  来源:igfitidea点击:

Find the index of a TabPage

vb.netwinformstabcontrol

提问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

You can use the method IndexOfof the TabPageCollection to get the Index of a Tab.

您可以使用TabPageCollection 的IndexOf方法来获取 Tab 的索引。

Dim indexOfTab As Integer = TabControl1.TabPages.IndexOf(tab)

回答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.

如果标签页曾经从集合中删除,但您想知道它在哪里,这将很有用。我知道这听起来很深奥,但我已经多次遇到这种情况,而且您无法从标签页对象本身获取此信息。