Vb.net Horazontal滚动条移动图片框Microsoft VB

Vb.net Horazontal滚动条移动图片框Microsoft VB,vb.net,picturebox,Vb.net,Picturebox,我有一个小乒乓球游戏,我正在做,我想让“桨”,这只是一个图片框上下移动时,我左右移动滚动条。我的滚动条代码如下: Private Sub HScrollBar1\u Scroll(发送方作为对象,e作为ScrollEventArgs)处理HScrollBar1.Scroll Me.picPlayer1.Location=新点(Me.picPlayer2.Location.X,Me.picPlayer2.Location.Y-HscrollBar1.Value*1) 末端接头 划桨似乎只向上移动,

我有一个小乒乓球游戏,我正在做,我想让“桨”,这只是一个图片框上下移动时,我左右移动滚动条。我的滚动条代码如下:

Private Sub HScrollBar1\u Scroll(发送方作为对象,e作为ScrollEventArgs)处理HScrollBar1.Scroll
Me.picPlayer1.Location=新点(Me.picPlayer2.Location.X,Me.picPlayer2.Location.Y-HscrollBar1.Value*1)
末端接头


划桨似乎只向上移动,但当我向左移动划桨时,它不应该向下移动吗?将默认值设置为50,最大值设置为100,因为您需要说明滚动的发生方式。您将始终返回一个带有代码的正数,而需要从其当前位置减去

 Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll

    Dim NewPos As Integer = e.NewValue
    Dim OldPos As Integer = e.OldValue

    Debug.WriteLine(NewPos, "My Current Value")
    Debug.WriteLine(OldPos, "My Previous Value")

    If NewPos > OldPos Then
        'Moving Up
        Me.PicPlayer1.Location = New Point(Me.PicPlayer1.Location.X, Me.PicPlayer1.Location.Y - HScrollBar1.Value * 1)
    Else
        'Moving Down
        Me.PicPlayer1.Location = New Point(Me.PicPlayer1.Location.X, Me.PicPlayer1.Location.Y - HScrollBar1.Value * -1)
    End If

End Sub
我发现另一个更好的解决方案

  Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll

        Dim NewPos As Integer = e.NewValue
        Dim OldPos As Integer = e.OldValue

        Debug.WriteLine(NewPos, "My Current Value")
        Debug.WriteLine(OldPos, "My Previous Value")

        Dim delta As Integer = Math.Abs(NewPos - OldPos)

        If NewPos > OldPos Then
            'Moving up
            Me.PicPlayer1.Location = New Point(Me.PicPlayer1.Location.X, Me.PicPlayer1.Location.Y - delta)
        Else

            'Moving down
            Me.PicPlayer1.Location = New Point(Me.PicPlayer1.Location.X, Me.PicPlayer1.Location.Y + delta)
        End If

    End Sub

非常感谢,我想当我发布它时,我只有积极的输出。但我还是不明白。我甚至试过做新的和旧的姿势,但都不起作用,一秒钟后我会试试这个。方向改变有延迟,有什么办法可以解决吗?在HScroolBar改变方向后,“划桨”不会立即停止并改变方向。我知道问题出在哪里,出于某种原因,我的编者没有编译我最近的脚本。如果你指出你不理解的部分,我会在我的回答中详细说明。