views:

234

answers:

2

I have a tree control that implements drag and drop. I use an overridden OnStartDrag() to get my own TDragObjectEx that shows an image while dragging. This works perfectly within the tree control, but as soon as I leave the tree control the image disappears. The cursor stays though.

I tried implementing OnDragOver, to reset the image but that does not appear to work.

Any hints on this? I am using C++ builder 2010, but delphi would do the same thing.

Update: Found setting csDisplayDragImage on each control in the form controls, and in form itself solves this issue. Is there some automated way to have csDisplayDragImage set in an entire form rather than have to set it manually in Create for each item?

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    ControlStyle << csDisplayDragImage;
    RMU->ControlStyle << csDisplayDragImage;
    Button1->ControlStyle << csDisplayDragImage;
}
+3  A: 

If I remember correct, you have to include the [csDisplayDragImage] flag in the "ControlStyle" of controls of which you want drag images to be seen when sth. is being dragged over them..

Update: setting "AlwaysShowDragImages" of the DragObject causes the drag image to be displayed all across the desktop.

Sertac Akyuz
Correct...turning AlwaysShowDragImages to true does the job.
gbrandt
A: 

Evidently, each control that's going to display the drag image needs to have the csDisplayDragImage control style set. You can add that flag to a control and all its chilren with a simple function:

void AddDisplayDragImageStyle(TControl* ctl)
{
  ctl->ControlStyle << csDisplayDragImage;
  TWinControl* win = dynamic_cast<TWinControl*>(ctl);
  if (win)
    for (int i = 0; i < win->ControlCount; ++i)
      AddDisplayDragImageStyle(win->Controls[i]);
}

Have the form call that on itself: AddDisplayDragImageStyle(this).

Rob Kennedy
This works, but setting AlwaysShowDragImages to true is much easier. Thanks.
gbrandt