Recent

Author Topic: [Solved] Custom component with drag-drop: issue on Windows  (Read 3961 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft
[Solved] Custom component with drag-drop: issue on Windows
« on: December 20, 2021, 08:24:23 am »
Can somebody please tell me what am I doing wrong?
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39515

This is affecting my main app.
« Last Edit: December 20, 2021, 11:54:13 am by Alextp »

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: My custom component with drag-drop: issue on Windows
« Reply #1 on: December 20, 2021, 10:58:45 am »
First of all you need this:
Code: Pascal  [Select][+][-]
  1. procedure TMyPanel.DragOver(Sender, Source: TObject;X,Y: Integer; State: TDragState; var Accept: Boolean);
  2. begin
  3.   Accept := True;
  4. end;  
  5.  
  6. constructor TMyPanel.Create(TheOwner: TComponent);
  7. begin
  8.   inherited Create(TheOwner);
  9.   FMouseDownPnt:= Point(-1, -1);
  10.   Cursor:= crIBeam;
  11.   OnDragOver := @DragOver;
  12. end;  
  13.  
Second - you need to do this:
Code: Pascal  [Select][+][-]
  1. procedure TMyPanel.UpdateCursor;
  2. begin
  3.   if Mouse.IsDragging then
  4.   begin
  5.     if ssCtrl in GetKeyShiftState then
  6.       DragCursor:= crMultiDrag
  7.     else
  8.       DragCursor:= crDrag;
  9.   end;
  10. end;
  11.  
Please note, that cursor actually changes only after mouse movement. I'm not sure, if it's correct way to do things. Something is still wrong, because cursor flickers. I guess, you mix some "auto" and "manual" drag and drop functionality.

« Last Edit: December 20, 2021, 11:14:00 am by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft
Re: My custom component with drag-drop: issue on Windows
« Reply #2 on: December 20, 2021, 11:53:52 am »
You are cool!
Thanks for the hint, I just added overloaded DragOver() method.
And 'DragCursor:=...'. Solved!

 

TinyPortal © 2005-2018