I'd like to do the following in an Excel/VBA form: There are two Frames on the form, side by side. Let's call them frame1
and frame2
. Inside frame1, there are other controls, say labels with text. What I'd like to do is to enable the user to grab one control from one frame and drag it into the other one, smoothly.
However, the control disappears upon dragging it out of frame1
. I tried to fiddle around with the ZOrder of the control and the frames but this doesn't help. Does anyone know if it is possible to drag something out of a frame (on a running form, of course) visibly, on top of everything else?
Thanks in advance!
Sorry for the delay, I wasn't at my desk yesterday.
I can show you what I have, but I'm not sure that this is the 'place' where to solve the issue. Anyway, we have frame1
and frame2
as described above, and inside frame1
, there is Label1
. I've given Label1
the usual mouse events for drag and drop:
Private x_offset%, y_offset%
Private Sub Label1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
If Button = XlMouseButton.xlPrimaryButton Then
x_offset = X
y_offset = Y
End If
End Sub
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
If Button = XlMouseButton.xlPrimaryButton Then
Label1.Left = Label1.Left + X - x_offset
Label1.Top = Label1.Top + Y - y_offset
End If
End Sub
That of course handles only the drag-and-drop part. I've tried setting the ZOrder of Label1
to solve this, but this doesn't actually do much here. Of course the parent of Label1 is the frame it's originally in, but the parent property is read-only.
Meanwhile I've also discovered that the drag-and-drop is not a problem if I place the labels not within frames but e.g. on top of other labels. I guess the frames just have this property of owning everything that's in them, and that ownership is not debatable during runtime. If anyone knows a way around this, I'd be grateful to know, but at least now I have a useable alternative.
Thanks again!