发新话题
打印

VB中如何使用MOVE事件来使一张图片移动到鼠标指定位置

定义有问题吧
我觉得是这样(虽然没试过)
Dim m As Varient, n As Varient(加根号后数是带许多带小数的)
还有我觉得这样好
  m = Image1.Left + (Image1.Left - Ix) / (image1.left-lx+image2.top)*Sqr((Image1.Left - Ix) * (Image1.Left - Ix) + (Image1.Top - Iy) * (Image1.Top - Iy))
那么移动的距离会相等。

TOP

Dim Ix As Variant, Iy As Variant

Private Sub Form_Activate()
Timer1.Enabled = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Ix = X
  Iy = Y
  Timer1.Enabled = Not Timer1.Enabled
End Sub

Private Sub Timer1_Timer()
Dim m As Variant, n As Variant
     m = Image1.Left - (Image1.Left - Ix) / Sqr((Image1.Left - Ix) * (Image1.Left - Ix) + (Image1.Top - Iy) * (Image1.Top - Iy))
    n = Image1.Top - (Image1.Top - Iy) / Sqr((Image1.Top - Iy) * (Image1.Top - Iy) + (Image1.Left - Ix) * (Image1.Left - Ix))
    If m = Ix And n = Iy Then
       Timer1.Enabled = False
    End If
Image1.Move m, n
End Sub
这次我试过了,成功了。

TOP

发新话题