Private
Sub Form_Load()
Sub Form_Load()
Image1.Picture = LoadPicture(Me.ImgPath)
FitForm Image1
Image1.Stretch = True
End Sub
Private Sub Form_Resize() Sub Form_Resize()
Call CenterImage(Image1)
End Sub
Private Sub Image1_MouseDown() Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
gX = X
gY = Y
End Sub
Private Sub Image1_MouseMove() 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
With Image1
dy = Y - gY
dx = X - gX
ll = .Left
tt = .Top
l = Abs(ll)
t = Abs(tt)
ax = (.Width - l - Frame1.Width)
ay = (.Height - t - Frame1.Height)
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
.Move ll + dx, tt + dy
End With
End Sub
Private Sub CenterImage() Sub CenterImage(dest As Image)
dest.Move 0, 0
End Sub
Private Sub FitForm() Sub FitForm(dest As Image)
dest.Width = dest.Width + Width - ScaleWidth
dest.Height = dest.Height + Height - ScaleHeight
dest.Move (Form1.Width - Width) / 2, (Form1.Height - Height) / 2
End Sub
Image1.Picture = LoadPicture(Me.ImgPath)
FitForm Image1
Image1.Stretch = True
End Sub
Private Sub Form_Resize() Sub Form_Resize()
Call CenterImage(Image1)
End Sub
Private Sub Image1_MouseDown() Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
gX = X
gY = Y
End Sub
Private Sub Image1_MouseMove() 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
With Image1
dy = Y - gY
dx = X - gX
ll = .Left
tt = .Top
l = Abs(ll)
t = Abs(tt)
ax = (.Width - l - Frame1.Width)
ay = (.Height - t - Frame1.Height)
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
.Move ll + dx, tt + dy
End With
End Sub
Private Sub CenterImage() Sub CenterImage(dest As Image)
dest.Move 0, 0
End Sub
Private Sub FitForm() Sub FitForm(dest As Image)
dest.Width = dest.Width + Width - ScaleWidth
dest.Height = dest.Height + Height - ScaleHeight
dest.Move (Form1.Width - Width) / 2, (Form1.Height - Height) / 2
End Sub