Drag and Drop with container control sub

I have a custom class object based on a ContainerControl that i want to drag and drop from one area to another. All is good except i want to retain a reference to that object so once the drop goes down ok i can delete it. The trouble with finding it afterwards without a direct ref to it is we go into the embedded window control abyss. Outside a reference elsewhere does anyone know how i can just add it to the DragItem? Is such a thing possible to do with raw data? Im not finding a lot of nuggets out there on this as the examples pass row numbers between knows listbox rows…

i used a property if me start the drag and remove it after drag.
i missed this feature to store a object at dragitem too.
in a property you can store a single item or a list (array) means everything you can memory there.

OT (Windows10)
if you find a way to appear the container control better at drag please let me know.
for me its nearly invisible at drag.

Thanks Markus,
What I wound up doing was to subclass the DragItem and add what I needed to the sub. Then, of course, call the subclass instead. The only hitch was to Cast the obj in the DropObject event as the subclass so to use the additions. works great.

on Win10 the drag item appears as a rectangle the same size as my object - is that what you’re seeing? so im ok with it right now but i plan to assign a picture of some sort to it later

how was that possible if this event method have
Sub DropObject(obj As DragItem, action As Integer) Handles DropObject
is it possible to change the object name DragItem there to MyDragItem?
OT
my drag is nearly invisible. i still think i do something wrong.

try this for the dragitem size:
New DragJob(Self, X, Y, Me.Width, Me.Height)

and then yes, subclass DragItem and declare that as i did above “DragJob” which is just a class with the parent of DragItem and i added a dragitem object property and assigned my DragJob to it when i instantiate it. Then, when it drops i just cast the “obj” like this: DragJob( obj ).mydragjobobjecttodelete and .close it because its a container control

myself starting the drag in one container control and i drop it on other container control class.
does your start drag looks similar?

Sub MouseDrag(X As Integer, Y As Integer) Handles MouseDrag
  
  CardDrag = Me '<- this is a global propety at a modul
  
  Var drag As New DragItem(Self, 0, 0, Me.Width, Me.Height)
  
  Var pic As New Picture(Me.Width,Me.Height)
  Me.DrawInto(pic.Graphics,0,0)
  
  drag.DragPicture = pic
  
  drag.MouseCursor = System.Cursors.FingerPointer
  
  drag.Text = "Card"
  
  If Abs(MouseDownMemory.Left -X)>16 Or Abs(MouseDownMemory.Right -Y)>16 Then
    drag.Drag
  End If
  
End Sub

what does “self” refer to in the dragitem instantiation? Var drag As New DragItem(Self, 0, 0, Me.Width, Me.Height) because you are getting the size w and h from “me”, but the dragitem object is "self’ - could that be a problem? Mine looks ok, its a rectangle but its decently visible and like i said i will add a picture to it later - but i would add it in the constructor:Constructor(r as RectControl, x as Integer, y as Integer, width as Integer, height as Integer, DragPicture as Picture)

1 Like

i guess because the position at screen.
it have a constructor with rectcontrol and the other with window.

All of this is from the Xojo documentation.

Me refers to the control that owns (or contains) the current event handler on a Window. Outside an event handler on a Window (such as within a method), it refers to the current object (Self).

When you refer to a property or method in your code without any sort of prefix, the one on the class itself (Self) is used by default.

For example, for any code contained on a window or web page, Self refers to the window or web page.


This code shows how to implement dragging the picture in a Canvas control. This example uses the Me keyword to refer to the Canvas control.

Function MouseDown(X As Integer, Y As Integer) As Boolean
Var d As DragItem
d = New DragItem(Self, X, Y, Me.Width, Me.Height)
d.Picture = Me.Backdrop
d.Drag // Allow the drag
End Function

without picture it is a good visible rectangle, with picture it fade out from mouse pointer to outer area.