|
Option Explicit
Private sngX As Single
Private sngY As Single
Private Sub Label1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Button Then Drag Label1, X, Y
End Sub
Private Sub Drag(Source As Control, X As Single, Y As Single)
sngX = X
sngY = Y
Source.DragMode = 1
Source.Drag vbBeginDrag
End Sub
Private Sub Frame1_DragDrop(Source As Control, _
X As Single, Y As Single)
Drop Frame1, Source, X, Y
End Sub
Private Sub Picture1_DragDrop(Source As Control, _
X As Single, Y As Single)
Drop Picture1, Source, X, Y
End Sub
Private Sub Drop(Target As Control, Source As Control, _
X As Single, Y As Single)
Set Source.Container = Target
With Source
.Drag vbEndDrag
.DragMode = 0
.Move X - sngX, Y - sngY
If TypeOf Target Is PictureBox Then
If .Left < 0 Then .Left = 0
If .Top < 0 Then .Top = 0
If .Left + .Width > Target.ScaleWidth Then
.Left = Target.ScaleWidth - .Width
End If
If .Top + .Height > Target.ScaleHeight Then
.Top = Target.ScaleHeight - .Height
End If
ElseIf TypeOf Target Is Frame Then
If .Left < 0 Then .Left = 10
If .Top < 30 Then .Top = 30
If .Left + .Width > Target.Width Then
.Left = (Target.Width - .Width) + 10
End If
If .Top + .Height > Target.Height Then
.Top = Target.Height - .Height
End If
Else
If .Left < 0 Then .Left = 0
If .Top < 0 Then .Top = 0
If .Left + .Width > Target.Width Then
.Left = Target.Width - .Width
End If
If .Top + .Height > Target.Height Then
.Top = Target.Height - .Height
End If
End If
End With
End Sub
|
|