核心提示:varDragFile,popfile//拖动的文件名procedureTfrmMain.lbxMyListClick(Sender:TObject); begin//单击时确定要拖动的文件名 ifT...
var DragFile,popfile:String;//拖动的文件名
procedure TfrmMain.lbxMyListClick(Sender: TObject);
begin //单击时确定要拖动的文件名
if TListbox(Sender).ItemIndex <>-1 then
Dragfile:=TListbox(Sender).Items[TListbox(Sender).itemIndex]
else
Dragfile:=’’;
end;
procedure TfrmMain.lbxMyListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
i,j:integer;
FileName:string;
MyPoint:TPoint;
begin //在列表框中拖动项目改变其位置
if DragFile<>’’ then
begin
MyPoint.X:=X; MyPoint.Y:=Y;
i:=TListbox(Sender).ItemAtPos(MyPoint,True);//获取要拖放到的位置
j:= TListbox(Sender).Items.IndexOf(DragFile);
if (i<>-1) and (j<>-1) and (i<>j) then
begin
TListbox(Sender).Items.Move(j,i);
TListbox(Sender).Selected[i]:=True;
end;
end;
end;