鼠标滚轮滚动与两个表格布局面板不一致

Mousewheel scroll inconsistent with two 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

找到了!

我需要包含 .PerformLayout

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