我有flowLayoutPanel有内容(控件)和两个按钮,一个在右边,另一个在左边 image
中的设计我想让布局面板滚动她的内容,右边的按钮向左,左边的按钮向左滚动,我该怎么办呢?
我使用此代码从顶部到底部执行此操作,但我需要它左右
代码是
Dim ypos As Integer
顶部按钮中的代码是
If ypos > flowLayoutPanel1.HorizontalScroll.Maximum - 451 Then
ypos = flowLayoutPanel1.HorizontalScroll.Maximum - 450
Else
ypos += 450
flowLayoutPanel1.AutoScrollPosition = New Point(0, ypos)
End If
和按钮按钮 如果ypos< 1然后 ypos = 0
Else
ypos -= 450
flowLayoutPanel1.AutoScrollPosition = New Point(0, ypos)
End If
由于
答案 0 :(得分:0)
在相应的左右按钮单击事件中增加和减少HorizontalScroll.Value
的值。
''' <summary>
''' determine the approx total width of all inner controls
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function approxInnerWidth() As Integer
Dim returnVal As Integer
For Each ctl As Control In ControlsFlowLayoutPanel.Controls
returnVal += ctl.Width
Next
Return returnVal
End Function
Private Sub LeftButton_Click(sender As System.Object, e As System.EventArgs) Handles LeftButton.Click
'scroll in 1/20th increments
Dim scrollVal = approxInnerWidth() \ 20
If ControlsFlowLayoutPanel.HorizontalScroll.Value > scrollVal Then
ControlsFlowLayoutPanel.HorizontalScroll.Value = ControlsFlowLayoutPanel.HorizontalScroll.Value - scrollVal
End If
End Sub
Private Sub RightButton_Click(sender As System.Object, e As System.EventArgs) Handles RightButton.Click
'scroll in 1/20th increments
Dim scrollVal = approxInnerWidth() \ 20
ControlsFlowLayoutPanel.HorizontalScroll.Value = ControlsFlowLayoutPanel.HorizontalScroll.Value + scrollVal
End Sub