TabControl选项卡显示 - Scoll进入视图

时间:2016-08-05 17:56:39

标签: vb.net winforms

我有一个WinForm TabControl,它有足够的标签,某些标签需要使用<滚动到视图中。 >的按钮。

作为备用操作,您可以单击最后一个可见选项卡,选项卡向左滚动以使该选项卡和下一个选项卡进入视图。这样可以正常工作,但是当您单击第一个(最左侧可见)选项卡时,不会发生相反的操作。预期的操作将使控件自动显示单击的选项卡和之前的选项卡。

我可以使用哪些事件或方法来查看TabPage的标签是否可见并将TabPage的标签滚动到屏幕上?

以下是一些研究代码:

Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
    If mbFormLoad Then Exit Sub
    Dim t As TabPage = TabControl1.SelectedTab
    Debug.Print(t.Name)
    Debug.Print("CanFocus:" & TabControl1.TabPages(0).CanFocus)
    Debug.Print("CanSelect:" & TabControl1.TabPages(0).CanSelect)
    Debug.Print("IsAccessible:" & TabControl1.TabPages(0).IsAccessible)
    ' works but causes screen noise
    If TabControl1.SelectedTab.TabIndex > 0 Then
        mbFormLoad = True
        TabControl1.SuspendLayout()
        TabControl1.SelectedIndex = TabControl1.SelectedTab.TabIndex - 1
        TabControl1.SelectedIndex = TabControl1.SelectedTab.TabIndex + 1
        TabControl1.ResumeLayout()
        mbFormLoad = False
    End If
End Sub

所有打印的属性都返回false。

要测试添加带有多个选项卡的tabcontrol,请显示表单并使其足够瘦以及< >按钮显示在右上方,滚动将第一个选项卡移出视图。

1 个答案:

答案 0 :(得分:0)

因为当您将selectedIndex设置为-1时,对tabcontrol1.selected tabindex的引用也会更改。

    'TabControl1.SelectedTab.TabIndex = 1
    TabControl1.SelectedIndex = TabControl1.SelectedTab.TabIndex - 1
    '1 - 1 = 0
    TabControl1.SelectedIndex = TabControl1.SelectedTab.TabIndex + 1
    '0 + 1 = 1


Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
    If mbFormLoad Then Exit Sub        
    Dim t As TabPage = TabControl1.SelectedTab
    Debug.Print(t.Name)
    Debug.Print("CanFocus:" & TabControl1.TabPages(0).CanFocus)
    Debug.Print("CanSelect:" & TabControl1.TabPages(0).CanSelect)
    Debug.Print("IsAccessible:" & TabControl1.TabPages(0).IsAccessible)
    ' works but causes screen noise
    If TabControl1.SelectedTab.TabIndex > 0 Then
        mbFormLoad = True
        TabControl1.SuspendLayout()

        'store the original selected tab index so you can work with an integer
        Dim index As Integer = TabControl1.SelectedTab.TabIndex

        TabControl1.SelectedIndex = index - 1
        TabControl1.SelectedIndex = index + 1
        TabControl1.SelectedIndex = index
        TabControl1.ResumeLayout()
        mbFormLoad = False
    End If