【问题标题】:Delphi Tokyo Firemonkey Drag Drop within same listboxDelphi Tokyo Firemonkey Drag Drop 在同一个列表框中
【发布时间】:2017-11-07 04:53:03
【问题描述】:
我有一个包含项目的列表框。
我需要用鼠标在同一个列表框中重新排列项目。
AllowDrag 设置为 true。
DragMode 是 dmManual。
Hittest 是真的。
仅当您首先通过单击然后释放鼠标左键选择项目,然后单击同一项目并拖放时才有效。
我在谷歌上搜索,看到其他人也有同样的问题,但没有找到解决方案。
如何在同一个 firemonkey 列表框中建立拖放功能?
【问题讨论】:
标签:
delphi
listbox
firemonkey
【解决方案1】:
我通过 MouseDown 事件和 FMX.Platform 单元的帮助来完成。
procedure TForm2.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
var
doData: TDragObject;
Svc : IFMXDragDropService;
Img : TBitmap;
begin
if Assigned(ListBox1.ItemByPoint(X, Y)) and TPlatformServices.Current.SupportsPlatformService(IFMXDragDropService, Svc) then
begin
doData.Source := ListBox1.ItemByPoint(X, Y);
Img := ListBox1.ItemByPoint(X, Y).MakeScreenshot;
Svc.BeginDragDrop(Self, doData, Img);
end;
end;