2016-08-05 79 views
2

我有一個WinForm TabControl有足夠的選項卡,需要使用<>按鈕將一些標籤滾動到視圖中。TabControl標籤顯示 - Scoll到視圖

作爲替代動作,您可以單擊最後一個可見選項卡,然後向左滾動選項卡以將該選項卡和下一個選項卡放入視圖中。這可以正常工作,但是當您單擊第一個(最左側的可見)選項卡時,不會發生相反的操作。預期的操作將使控件自動顯示點擊標籤和之前的標籤。

我可以使用哪些事件或方法來查看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與幾個選項卡,顯示窗體,並使其足夠瘦,<>按鈕顯示在右上角和滾動移動的第一個標籤的視圖。

回答

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