这是一个当图片大于窗体时,用鼠标移动多余部分的代码?Private Sub Form_Load()
Image1 = LoadPicture("f:\bbs\tu\01.jpg") '这个路径可能要改
'FitForm Image1
End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
gX = X
gY = Y
End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Button = vbLeftButton Then Exit Sub
Dim dx As Long, dy As Long, ax As Long, ay As Long, t As Long, l As Long, tt As Long, ll As Long 'dy = Y - gY
dx = X - gX
ll = Image1.Left
'tt = Image1.Top
l = Abs(ll)
't = Abs(tt)
ax = (Image1.Width - l - ScaleWidth)
'ay = (Image1.Height - t - ScaleHeight)
If ll > 0 Then
dx = 0
Else
If dx < 0 Then
If Abs(dx) > ax Then dx = -ax
Else
If dx > l Then dx = l
End If
End If
'If tt > 0 Then
'dy = 0
'Else
'If dy < 0 Then
'If Abs(dy) > ay Then dy = -ay
'Else
'If dy > t Then dy = t
' End If
'End If
Image1.Move ll + dx 'tt + dyEnd Sub
Image1 = LoadPicture("f:\bbs\tu\01.jpg") '这个路径可能要改
'FitForm Image1
End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
gX = X
gY = Y
End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Button = vbLeftButton Then Exit Sub
Dim dx As Long, dy As Long, ax As Long, ay As Long, t As Long, l As Long, tt As Long, ll As Long 'dy = Y - gY
dx = X - gX
ll = Image1.Left
'tt = Image1.Top
l = Abs(ll)
't = Abs(tt)
ax = (Image1.Width - l - ScaleWidth)
'ay = (Image1.Height - t - ScaleHeight)
If ll > 0 Then
dx = 0
Else
If dx < 0 Then
If Abs(dx) > ax Then dx = -ax
Else
If dx > l Then dx = l
End If
End If
'If tt > 0 Then
'dy = 0
'Else
'If dy < 0 Then
'If Abs(dy) > ay Then dy = -ay
'Else
'If dy > t Then dy = t
' End If
'End If
Image1.Move ll + dx 'tt + dyEnd Sub
这段代码有防止移出界的功能,边运行边看应该能够理解。