2015-02-24 15 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 

回答