如何测试在 VB.net TabControl 中选择了哪个选项卡

发布于 2024-08-05 05:35:58 字数 83 浏览 7 评论 0原文

我有一个带有两个 TabPage 的 TabControl,我想知道测试当前显示哪个选项卡的最佳方法是什么?我不知道为什么我无法弄清楚这一点......

I have a TabControl with two TabPages and I was wondering what is the best way to test which tab is currently displayed? I'm not sure why I can't figure this one out...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

饮惑 2024-08-12 05:35:59

如果您使用 .Net 3.5,则可以根据需要创建 IsSelected 方法作为扩展方法:

Public Module TabControlExtensions
    <Extension()> _
    Public Function IsSelected(ByVal tabPage As TabPage) As Boolean
        Dim tabControl = CType(tabPage.Parent, TabControl)
        Return (tabControl.SelectedTab Is tabPage)
    End Function
End Module

If you use .Net 3.5, you can create a IsSelected method as an extension method if you wish:

Public Module TabControlExtensions
    <Extension()> _
    Public Function IsSelected(ByVal tabPage As TabPage) As Boolean
        Dim tabControl = CType(tabPage.Parent, TabControl)
        Return (tabControl.SelectedTab Is tabPage)
    End Function
End Module
百合的盛世恋 2024-08-12 05:35:59

假设这是一个 WPF 应用程序,请确保每个 TabItem 都有一个名称。

然后只需检查即可。

if tabItem1.IsSelected = true then
  ' Do Something 
else if tabItem2.IsSelected = true then
  ' Do Something 
end if 

Assuming this is a WPF application, make sure that each TabItem has an Name.

Then it's just a matter of checking.

if tabItem1.IsSelected = true then
  ' Do Something 
else if tabItem2.IsSelected = true then
  ' Do Something 
end if 
下壹個目標 2024-08-12 05:35:59

试试这个..

这是在选择每个选项卡时如何修改
那么每个选项卡都会有一个功能

第一评分|第二评分|

Private Sub TabControlAction(ByVal sender As Object, ByVal e As System.EventArgs) Handles nameoftab.Click

        If nameoftab.SelectedTab.Text = "Second Grading" Then
            Msgbox("Second Grading is Selected")
''Place whatever your want

        Else
            Msgbox("First Grading is Selected")
''Place whatever your want
        End If

    End Sub

不过你可以使用if elseif else语句。

这个发现对我有用。

Try This..

this is how to modify each of the tab when selected
then there will be a function of each tab

First Grading |Second Grading |

Private Sub TabControlAction(ByVal sender As Object, ByVal e As System.EventArgs) Handles nameoftab.Click

        If nameoftab.SelectedTab.Text = "Second Grading" Then
            Msgbox("Second Grading is Selected")
''Place whatever your want

        Else
            Msgbox("First Grading is Selected")
''Place whatever your want
        End If

    End Sub

You can use if elseif else statement though.

this find works for me.

为人所爱 2024-08-12 05:35:59

尝试使用 TabPages 集合编辑器为每个单独的选项卡设置“TAG”属性。将每个标签设置为代表 Tab 序列的数字(从 1 或 0 或任何适合的数字开始)

Private Sub TabControl1_Click(sender As Object, e As System.EventArgs) Handles TabControl1.Click

    Dim ActiveTabNumber as Integer = TabControl1.SelectedTab.Tag

End Sub

Try setting the "TAG" propety for each individual tab using the TabPages collection editor. Set each tag to a number representing the Tab sequence (starting at 1 or 0 or whatever to suit)

Private Sub TabControl1_Click(sender As Object, e As System.EventArgs) Handles TabControl1.Click

    Dim ActiveTabNumber as Integer = TabControl1.SelectedTab.Tag

End Sub
公布 2024-08-12 05:35:59
TabControl1_Click:
    If TabControl1.SelectedIndex = 0 Then
        ' Do Something       
    ElseIf TabControl1.SelectedIndex = 1 Then
        ' Do Something 
    End If
End Sub
TabControl1_Click:
    If TabControl1.SelectedIndex = 0 Then
        ' Do Something       
    ElseIf TabControl1.SelectedIndex = 1 Then
        ' Do Something 
    End If
End Sub
风吹短裙飘 2024-08-12 05:35:59

我有一个名为 tcMode 的 TabControl,其中包含名为 tcmRelease 和 tcmSwitch 的成员/项目,并且以下内容对我来说效果很好,能够无忧地移动选项卡/重命名;

If tcMode.SelectedTab Is tcmRelease Then
      'Do Something if first tab selected
ElseIf tcMode.SelectedTab Is tcmSwitch Then
      'Do something if second tab selected
End If

选项卡控件成员的图像

I have a TabControl called tcMode, with members/items called tcmRelease and tcmSwitch, and the following works nicely for me with the ability to move the tabs around/rename without worrying;

If tcMode.SelectedTab Is tcmRelease Then
      'Do Something if first tab selected
ElseIf tcMode.SelectedTab Is tcmSwitch Then
      'Do something if second tab selected
End If

Image of Tab Control Members

不弃不离 2024-08-12 05:35:59

还可以执行以下操作:

Dim TabName As String

TabName = YourTabControl.SelectedTab.Name

If TabName.Contains("YourTabName") Then
    ' Do something
End If

Can also do the following:

Dim TabName As String

TabName = YourTabControl.SelectedTab.Name

If TabName.Contains("YourTabName") Then
    ' Do something
End If
渔村楼浪 2024-08-12 05:35:59

此代码将显示当前选定的选项卡名称

 Private Sub Tab_new1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Tab_new1.SelectedIndexChanged
        MsgBox(Tab_new1.SelectedTab.Name)
    End Sub

This code will show the current selected tab name

 Private Sub Tab_new1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Tab_new1.SelectedIndexChanged
        MsgBox(Tab_new1.SelectedTab.Name)
    End Sub
眼趣 2024-08-12 05:35:58
Private Sub TabControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl.SelectedIndexChanged
    If TabControl.SelectedTab Is tabMyTab Then
        ' do whatever...
    End If
End Sub
Private Sub TabControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl.SelectedIndexChanged
    If TabControl.SelectedTab Is tabMyTab Then
        ' do whatever...
    End If
End Sub
尾戒 2024-08-12 05:35:58

使用该选项卡的“ENTER EVENT”
例如。

   Private Sub TabName_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabName.Enter
        MsgBox("me the tab selected")
         'or do whattever u like
    End Sub

use that tab's "ENTER EVENT "
eg.

   Private Sub TabName_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabName.Enter
        MsgBox("me the tab selected")
         'or do whattever u like
    End Sub
拍不死你 2024-08-12 05:35:58
TabControl.SelectedTab.

这是链接

TabControl.SelectedTab.

Here's the link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文