下面的代码使用ListBox实现像Winamp那样的拖放改变顺序.
var
isdown: boolean;
procedure Tripmain.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
source:=ListBox1.ItemAtPos(point(x,y),false);
isdown:=true;
end;
procedure Tripmain.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
isdown:=false;
end;
procedure Tripmain.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if isdown then
begin
target:=ListBox1.ItemAtPos(point(x,y),false);
if (source<>target) and (target>=0) then
begin
ListBox1.Items.Exchange(target,source);
source:=target;
end;
end;
end;