Option Explicit
Private WithEvents imEvents As MSForms.Image
Private oForm As MSForms.UserForm
' _____________________________________ CLASS METHODS _____________________________________________
Public Property Set ParentForm(ByVal vNewValue As MSForms.UserForm)
Dim imHolder As MSForms.Image
Set oForm = vNewValue
On Error Resume Next
Set imHolder = oForm.Controls("imgHolder")
On Error GoTo 0
If imHolder Is Nothing Then
Set imHolder = oForm.Add("Forms.image.1", "imgHolder", False)
With imHolder
.Width = 0&
.Height = 0&
.Top = -500&
.Left = -500&
End With
End If
End Property
Public Property Set Image(ByVal vNewValue As MSForms.Image)
Set imEvents = vNewValue
End Property
' _____________________________________ EVENTS _____________________________________________
Private Sub imEvents_MouseDown( _
ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single _
)
Dim MyDataObject As MSForms.DataObject, imgHolder As MSForms.Image
If Not imEvents.Picture Is Nothing Then
If Button = 1& Then
Set MyDataObject = New MSForms.DataObject
On Error Resume Next
Set imgHolder = oForm.Controls("imgHolder")
On Error GoTo 0
If Not imgHolder Is Nothing Then
Set imgHolder = oForm.Controls("imgHolder")
Set imgHolder.Picture = imEvents.Picture
imgHolder.Tag = imEvents.Name
End If
Call MyDataObject.StartDrag
End If
End If
End Sub
Private Sub imEvents_BeforeDragOver( _
ByVal Cancel As MSForms.ReturnBoolean, _
ByVal Data As MSForms.DataObject, _
ByVal X As Single, _
ByVal Y As Single, _
ByVal DragState As MSForms.fmDragState, _
ByVal Effect As MSForms.ReturnEffect, _
ByVal Shift As Integer _
)
Cancel = True
End Sub
Private Sub imEvents_BeforeDropOrPaste( _
ByVal Cancel As MSForms.ReturnBoolean, _
ByVal Action As MSForms.fmAction, _
ByVal Data As MSForms.DataObject, _
ByVal X As Single, _
ByVal Y As Single, _
ByVal Effect As MSForms.ReturnEffect, _
ByVal MaskKeys As Integer _
)
Dim imgHolder As MSForms.Image
On Error Resume Next
Set imgHolder = oForm.Controls("imgHolder")
On Error GoTo 0
With oForm
If Not imgHolder Is Nothing Then
.DesignMode = fmModeOn
Select Case MaskKeys And 7&
Case Is = 1& 'Move Image (press SHIFT Key)
.Controls(imgHolder.Tag).Picture = Nothing
Set imEvents.Picture = imgHolder.Picture
Case Is = 2& 'Copy Image (press CTRL Key)
Set imEvents.Picture = imgHolder.Picture
Case Is = 4& 'Swap Images (press ALT Key)
.Controls(imgHolder.Tag).Picture = imEvents.Picture
Set imEvents.Picture = imgHolder.Picture
End Select
.DesignMode = fmModeOff
.Repaint
End If
End With
End Sub