SendMessage: Move Object on X position only
Hello,
Trying to move an object inside Picturebox borders.
I've tried a few methods, with get/setcapture etc.. the following works best only if I could limit the dragging to the X position of the mouse?
Code:
ReleaseCapture
SendMessage picDraw.hwnd, &H112, &HF012&, 0
Is there a way to intervene and set the x/y pos?
Re: SendMessage: Move Object on X position only
I don't think you can override that unless you also subclass the control. But there's a very easy solution.
Code:
Option Explicit
Dim m_DragX As Single
Dim m_Dragging As Boolean
Private Sub picDraw_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
m_Dragging = True
m_DragX = X
End If
End Sub
Private Sub picDraw_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If m_Dragging Then picDraw.Left = (picDraw.Left - m_DragX) + X
End Sub
Private Sub picDraw_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
m_Dragging = False
End Sub