如果按left键以及image1的左边减105大于0,则image1左移105
如果按right键以及image1的左边加image1的宽度加105小于窗体的scalewidth,则image1右移105

解决方案 »

  1.   

    该段代码通过API函数获取按键,来实现通过左右箭头键来控制图片左右移动。
      

  2.   

    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer'就是在没有获得焦点的情况下也可以移动图片Image1
    Private Sub Form_Load()
    Timer1.Interval = 100
    End SubPrivate Sub Timer1_Timer()If GetKeyState(vbKeyLeft) < 0 Then
        If Image1.Left - 105 > 0 Then
            Image1.Left = Image1.Left - 105
        End If
    End IfIf GetKeyState(vbKeyRight) < 0 Then
        If Image1.Left + Image1.Width + 105 < Me.ScaleWidth Then
            Image1.Left = Image1.Left + 105
        End If
    End IfEnd Sub