I have one big picturebox of the house plan. for the sake of example, assume it is 1600 * 1200 pixels.
And on the most top and left of that house plan (position top 0 and left 0), I have another small picturebox of desk (let's say, 30* 30 pixels).

I want to move that desk to the desired its desired place in the plan (let's say, top 50, left 100).

I have bigPicture_MouseUp, bigPicture_MouseDown, Timer1_Timer.
I am able to click everywhere in bigPicture, except the 30*30 in the top left because that area is covered by the small picture.

I need to get access to every points in bigPicture... but if it is covered by the small picture, I cannot even know how to detect it...

Maybe, I just need to let the program notice, when the point hit something that not in the big picture... but, I'm clueless...

Do you have any hint? thanks

Dani AI

Generated

Quick summary: was right — treat the small desk PictureBox as the draggable object and handle its mouse events. Record the mouse offset on MouseDown, move the control during MouseMove while a “dragging” flag is set, and clear the flag on MouseUp. Keep the math in the same coordinate units as the PictureBox (set ScaleMode to pixels to simplify things) and clamp the new Left/Top so the desk never leaves the plan area.

A minimal VB6 example (change names to match your controls):

' form-level
Private dragging As Boolean
Private dragOffsetX As Single, dragOffsetY As Single

Private Sub picDesk_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        dragging = True
        dragOffsetX = X: dragOffsetY = Y
    End If
End Sub

Private Sub picDesk_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Not dragging Then Exit Sub
    Dim absX As Single, absY As Single
    absX = picDesk.Left + X: absY = picDesk.Top + Y
    Dim newLeft As Single, newTop As Single
    newLeft = absX - dragOffsetX: newTop = absY - dragOffsetY

    ' constrain to picPlan bounds
    If newLeft < picPlan.Left Then newLeft = picPlan.Left
    If newTop  < picPlan.Top  Then newTop  = picPlan.Top
    If newLeft > picPlan.Left + picPlan.Width  - picDesk.Width  Then newLeft = picPlan.Left + picPlan.Width  - picDesk.Width
    If newTop  > picPlan.Top  + picPlan.Height - picDesk.Height Then newTop  = picPlan.Top  + picPlan.Height - picDesk.Height

    picDesk.Left = newLeft: picDesk.Top = newTop
End Sub

Private Sub picDesk_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    dragging = False
End Sub

On saving: compose the final image into a single off‑screen canvas (a hidden PictureBox sized to the plan). Paint the plan image onto that canvas, then PaintPicture each overlay (desk, chairs, etc.) at positions translated to canvas coordinates (control.Left - plan.Left, control.Top - plan.Top). Once everything is painted to the off‑screen image you can write that image to disk with a suitable encoder. If you need JPEG output, use a small JPEG encoder/GDI+ wrapper or a conversion step — VB6’s built‑in routines don’t produce JPEG directly.

Troubleshooting tips: use a pixel ScaleMode to avoid unit conversion bugs; enable AutoRedraw or use an off‑screen canvas to avoid flicker while dragging; handle transparent overlay images by using masks or preprocessed bitmaps if PaintPicture does not respect alpha; and, to let clicks on the desk trigger the same logic as clicks on the plan, compute the desk-relative point in plan coordinates and call your central placement routine directly. ’s links about moving controls are a good reference for variations on the drag pattern.

Recommended Answers

All 4 Replies

(hint) The small picture box has the same events as the large picture box...

Good Luck

thanks for replying, yup, I replicate the same behavior to the smaller picture and it solved.

Another thing is, when the picture is done, I want to save them as jpeg, what should I do?

I used bigpicture.Picture = bigpicture.Image
and used SavePicture bigPicture.picture, "file location"

but I can only save the plain one.
Should I use paintpicture method, and paint the small pictures one by one into the bigpicture before saving it?
Is it the only way to do it?

Thanks

The SavePicture function can only save pictures as bitmaps. You will need to look into GDI+ (see strongm's post at the bottom of this thread ) or perhaps one of the dll's out there ( ) and then there is WIA (see strongm's post in this thread )

Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.