首先将listbox的属性:
DrogMod 设置为dmAutomatic
Multiselect 设置为 true
代码:
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
i:integer;
str:string;
begin
for i:= tlistbox(source).items.count-1 downto 0 do
begin
if tlistbox(source).Selected[i] then
begin
with source as tlistbox do
begin
str:=items[i];
items.Delete(i);
end;
with sender as tlistbox do
begin
items.Insert(itematpos(point(x,y),false),str);
end;
end;
end;
end;
procedure TForm1.ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
accept:=false;
if source is tlistbox then
with source as tlistbox do
if items.Count>0 then
accept:=true;
end;