鼠标滚轮滚动与两个tablelayoutpanels不一致

时间:2015-02-24 15:15:15

标签: vb.net scroll mousewheel tablelayoutpanel

我有两个桌面布局。 两个面板的滚动事件都是链接的,因此用户滚动一个,另一个滚动。这很好用:

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

1 个答案:

答案 0 :(得分:0)

发现它!

https://stackoverflow.com/a/5565804/3953342

我需要包含.PerformLayout

Layout_SidePanel.VerticalScroll.Value = Layout_Calendar.VerticalScroll.Value
Layout_SidePanel.PerformLayout()