2015-02-24 48 views
1

我有兩個tablelayoutpanels並排。 兩個面板的滾動事件都是鏈接的,所以用戶也滾動一個滾動條和另一個滾動條。這工作正常:滾輪滾動與兩個tablelayoutpanels不一致

Private Sub Layout_SidePanel_Scroll(sender As Object, e As ScrollEventArgs) Handles Layout_SidePanel.Scroll 

    If e.ScrollOrientation = ScrollOrientation.VerticalScroll Then 
     'make the other panel scroll too 
     Layout_Main.VerticalScroll.Value = Layout_SidePanel.VerticalScroll.Value 

    End If 
End Sub 

Private Sub Layout_Main_Scroll(sender As Object, e As ScrollEventArgs) Handles Layout_Main.Scroll 

    If e.ScrollOrientation = ScrollOrientation.VerticalScroll Then 
     'make the other panel scroll too 
     Layout_SidePanel.VerticalScroll.Value = Layout_Main.VerticalScroll.Value 
    End If 

End Sub 

但是,當用戶使用鼠標滾輪來滾動它不能正常工作。一邊會滾動而不滾動另一邊。或者一個會比另一個滾動多一點。我檢查了兩個面板的垂直滾動值,可以看到它們不匹配。我需要讓滾動工作一致或禁用鼠標滾輪。 這是我的代碼交給鼠標滾輪事件:

 Private Sub Layout_Main_MouseWheel(sender As Object, e As MouseEventArgs) Handles Layout_Main.MouseWheel 

    Layout_SidePanel.VerticalScroll.Value = Layout_Main.VerticalScroll.Value 

End Sub 

Private Sub Layout_Sidepanel_MouseWheel(sender As Object, e As MouseEventArgs) Handles Layout_SidePanel.MouseWheel 

    Layout_Main.VerticalScroll.Value = Layout_SidePanel.VerticalScroll.Value 

End Sub 

回答