I have a picturebox that contains an image. I have another object which is a UC. When I mouse down and then mouse move on the picturebox it causes the UC control to move to a pre-defined location (specified by someX and someY) . This works great for the first time. Now I can also move the UC manually. So if I now take the UC from it's current position (the position it was moved to by clicking on Picture1) and manually move it to another location and then click again on the picturebox the UC control will not move to someX and someY.
Here is the entire code
Form Code:
UserControl code:
Here is the entire code
Form Code:
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
UC1.ZOrder 0
UC1.Move someX, someY
UC1_MouseMove Button, Shift, X, Y
End If
End Sub
Private Sub UC1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
UCimg1(Index).ZOrder 0
If Button = vbLeftButton Then
ReleaseCapture
SendMessage UCimg1(Index).hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End If
End Sub
UserControl code:
Code:
Option Explicit
Public Event Click()
Public Event DblClick()
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event OLECompleteDrag(Effect As Long)
Public Event OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
Public Event OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)
Public Event OLESetData(Data As DataObject, DataFormat As Integer)
Public Event OLEStartDrag(Data As DataObject, AllowedEffects As Long)
Private Sub UserControl_Initialize()
UserControl.BackColor = vbWhite
UserControl.BackStyle = 0
Redraw
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Set Picture = PropBag.ReadProperty("Picture", Nothing)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "Picture", Picture, Nothing
End Sub
Private Sub UserControl_Resize()
Redraw
End Sub
Public Property Let Picture(newPic As StdPicture)
' this calls the Set Picture() method below, no code needed here.
End Property
Public Property Set Picture(newPic As StdPicture)
On Error Resume Next
Set UserControl.Picture = newPic
Redraw
PropertyChanged "Picture"
End Property
Public Property Get Picture() As StdPicture
Set Picture = UserControl.Picture
End Property
Public Property Get hWnd() As Long
hWnd = UserControl.hWnd
End Property
Public Sub Redraw()
UserControl.MaskColor = UserControl.BackColor
Set UserControl.MaskPicture = UserControl.Image
UserControl.Refresh
End Sub
Private Sub UserControl_Click()
RaiseEvent Click
End Sub
Private Sub UserControl_DblClick()
RaiseEvent DblClick
End Sub
Private Sub UserControl_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
RaiseEvent DragOver(Source, X, Y, State)
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub
Private Sub UserControl_OLECompleteDrag(Effect As Long)
RaiseEvent OLECompleteDrag(Effect)
End Sub
Private Sub UserControl_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent OLEDragDrop(Data, Effect, Button, Shift, X, Y)
End Sub
Private Sub UserControl_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
RaiseEvent OLEDragOver(Data, Effect, Button, Shift, X, Y, State)
End Sub
Private Sub UserControl_OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)
RaiseEvent OLEGiveFeedback(Effect, DefaultCursors)
End Sub
Private Sub UserControl_OLESetData(Data As DataObject, DataFormat As Integer)
RaiseEvent OLESetData(Data, DataFormat)
End Sub
Private Sub UserControl_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
RaiseEvent OLEStartDrag(Data, AllowedEffects)
End Sub