Drag and Drop in Autoscrolling control: drag image smearing

I wanted to implement drag and drop and autoscrolling (when the cursor is
over a hot zone near the top or the bottom edge) in a TCustomListBox
descendant (a Raize Components TRzCheckList descendant, to be more accurate).

Thanks to a post in this NG from Jim Wowchuk, I could do most of the work
until I ran into a snag: my ListBox provides a drag image, and this image
seems to be considered part of the canvas so when the list is scrolled, a
'ghost' of the cursor and the drag image gets smeared over the ListBox (note:
in Jim's solution, the hot zones are outside the control; in mine, they are
inside).

Co-workers here tried this in a TreeView (which can also provides a drag
image) and had the same problem.  After much trial and error, here is the
solution:

var
  VDragImages: TImageList;

...

{ Put this where you would scroll the control ( ListBox, TreeView, etc. ) }
VDragImages := nil;
VDragImages := {The source of the drag}.GetDragImages;
if Assigned( VDragImages ) then VDragImages.HideDragImage;
try
  {your TControl}.Perform( WM_VSCROLL, SB_LINEUP, 0 );
  { or {your TControl}.Perform( WM_VSCROLL, SB_LINEDOWN, 0 ) }
  { or any appropriate way to scroll the control, }
  { such as TListBox.TopIndex }
finally
  if Assigned( VDragImages ) then VDragImages.ShowDragImage;
end;

...

If you want more details, you can reach me at
Sebastien_Chouin...@abcdef.baan.com.  Be sure to remove the 'abcdef.' part
from the address before sending.

    -----

    Sebastien Chouinard
    Software Engineer
    Baan Supply Chain Solutions

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading