如题:可以实现随意拖动并保持图标的位置

解决方案 »

  1.   

    你的意思是拖动一个NOde??
    在OnDrag里边写啊
      

  2.   

    实现 windows 桌面上拖动图标的界面
    宋体   如何实现 windows 桌面上拖动图标的界面 宋体  // 用 TListView 把 TListView 放在 form 上 ,设定 align:=alclient;添加几个 ListItem,设定大图标 ,ListView.viewstyle:=vsicon下面是代码 unit Unit1;
    interface
    usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ImgList, ComCtrls;
    typeTForm1 = class(TForm)fghd: TListView;ImageList1: TImageList;procedure fghdDragOver(Sender, Source: TObject; X, Y: Integer;State: TDragState; var Accept: Boolean);procedure fghdDragDrop(Sender, Source: TObject; X, Y: Integer);procedure fghdMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);private{ Private declarations }public{ Public declarations }end;
    varForm1: TForm1;
    implementation
    {$R *.DFM}
    procedure TForm1.fghdDragOver(Sender, Source: TObject; X, Y: Integer;State: TDragState; var Accept: Boolean);beginaccept:=Source is TlistViewend;
    procedure TForm1.fghdDragDrop(Sender, Source: TObject; X, Y: Integer);varPosPoint:TPoint;beginPosPoint.x:=x;PosPoint.y:=Y;(Source As TListView).Selected.SetPosition(PosPoint);end;
    procedure TForm1.fghdMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);beginif button=mbleft thenbeginwith sender as TListview dobeginif GetItemAt(x,y)<>nil thenbegindrag(false);end;end;end;
    end.
      

  3.   

    lion_lh(xmanx) :可以拖动,但拖动位置不精确,能不能控制精确些,多谢!~
      

  4.   

    我也遇到过这样的问题
    这样解决的:
    在程序里声明两个变量fx,fy : integer
    在fghdMouseDown里加上
    fx:=x-(Source As TListView).Selected.left
    fy:=y-(Source As TListView).Selected.top
    在fghdDragDrop里改为
    PosPoint.x:=x-fx;
    PosPoint.y:=Y-fy;