在FORM1上放一个ListView1,建立几个Items,一个ImageList1,ImageList1里面放几个图标~~ 设置ListView1.LargeImages :=ImageList1;procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin accept:=Source is TlistView; end;procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer); var PosPoint:TPoint; begin PosPoint.x:=X-16; PosPoint.y:=Y-16; (Source As TListView).Selected.SetPosition(PosPoint); end;procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if button=mbleft then begin with sender as TListview do begin if GetItemAt(x,y)<>nil then begindrag(false); end; end; end;可以拖动一个Item。 至于多个Item的拖动我也还在识。
哈哈,搞定sx,sy: integer;procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin accept:=Source is TlistView; end;procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer); var i:integer; PosPoint:Tpoint; begin sx:=sx-x; sy:=sy-Y; with sender as TListview do for i:=0 to Items.Count-1 do if Items[i].Selected then begin PosPoint.x:=Items[i].Left - sx; PosPoint.y:=Items[i].Top - sy; Items[i].SetPosition(PosPoint); end; Refresh; end;procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if button=mbleft then with sender as TListview do if GetItemAt(x,y)<>nil then begindrag(false); sx:=x; sy:=y; end;
设置ListView1.LargeImages :=ImageList1;procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
accept:=Source is TlistView;
end;procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
PosPoint:TPoint;
begin
PosPoint.x:=X-16;
PosPoint.y:=Y-16;
(Source As TListView).Selected.SetPosition(PosPoint);
end;procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if button=mbleft then
begin
with sender as TListview do
begin
if GetItemAt(x,y)<>nil then
begindrag(false);
end;
end;
end;可以拖动一个Item。
至于多个Item的拖动我也还在识。
State: TDragState; var Accept: Boolean);
begin
accept:=Source is TlistView;
end;procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
i:integer;
PosPoint:Tpoint;
begin
sx:=sx-x;
sy:=sy-Y;
with sender as TListview do
for i:=0 to Items.Count-1 do
if Items[i].Selected then
begin
PosPoint.x:=Items[i].Left - sx;
PosPoint.y:=Items[i].Top - sy;
Items[i].SetPosition(PosPoint);
end;
Refresh;
end;procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if button=mbleft then
with sender as TListview do
if GetItemAt(x,y)<>nil then begindrag(false);
sx:=x; sy:=y;
end;
虽然你没有直接的解决了我的问题(可能是你还没有理解清楚我的意图吧),我要的是类似把文件考进目录用拖动来完成的。而你给我的代码是关于如何把一个文件放到其它地方去。不过在你的代码给了我很大的启示。使我能顺利的完成任务。你要是想我的代码的话可以给我mail。我的mail:[email protected],希望我们能够经常交流一起成长。再次感谢你。