neruos wrote:
Jasmine: That is exactly what I wanted! You didn't have to go thru the trouble, but it is much appreitated, I'm sure many others might benefit from this!

I do notice that you can drag the rects OUTSIDE the rect, can this be eliminated by doing a ptinrect over the current focus rect?
Yeah, the dragging wasn't really part of the demo. It was added only so you can move stuff around to see the zordering at work
This is the dragging code at the moment:
Code:
If Button = 1 Then
i = sort(1)
rect(i).X = rect(i).X + X - dragx
rect(i).Y = rect(i).Y + Y - dragy
dragx = X: dragy = Y
redraw
End If
The dragging works by moving the highest rect whenever the mouse drags.
To perfect the dragging I'd create another variable to track which rectangle is being dragged, and set this in the mouse_down.
this is totally untested, but something like:
Code:
Dim DraggedRect as Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 1:
dragx = X: dragy = Y
DraggedRect = WhichRect(X, Y)
SendToFront DraggedRect
Case 2:
DeleteRect WhichRect(X, Y)
End Select
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 and DraggedRect>0 Then
i = DraggedRect
rect(i).X = rect(i).X + X - dragx
rect(i).Y = rect(i).Y + Y - dragy
dragx = X: dragy = Y
redraw
End If
End Sub