• Move ListBox Items with the Mouse (Drag and Drop


    {Move ListBox Items with the Mouse (Drag and Drop). 
        1,Drop a TListBox (named ListBox1) on a form
        2,Add several strings using the Items property
        3,Set ListBox1's DragMode to dmAutomatic (in Form's OnCreate or using Object Inspector at design-time).
        4,Handle LisBox-es MouseDown, DragOver and DragDrop events    

        在同一个listbox中实现
    }



    var
      Form1: TForm1;
      StartingPoint : TPoint;//

    procedure TForm1.FormCreate(Sender: TObject);
    begin
        ListBox1.DragMode := dmAutomatic;
    end;

    procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
    var
        DropPosition, StartPosition: Integer;
        DropPoint: TPoint;
     begin
        DropPoint.X := X;
        DropPoint.Y := Y;
        with Source as TListBox do
        begin
          StartPosition := ItemAtPos(StartingPoint,True) ;
          DropPosition := ItemAtPos(DropPoint,True) ;
          Items.Move(StartPosition, DropPosition) ;
        end;
     end;

     procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    begin
        Accept := Source = ListBox1;
    end;

    procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
        StartingPoint.X := X;
        StartingPoint.Y := Y;
    end;




  • 相关阅读:
    常见浏览器的兼容问题以及解决方案 (仅供参考)
    了解浏览器如何工作—渲染引擎1
    维基百科公式不能正常显示
    IDL读取fits文件
    卷积,系统
    硬盘被占用无法拔出问题解决
    Faster RCNN 改进论文及资料
    Pycharm 使用问题一览
    java eclipse 使用随笔
    Images
  • 原文地址:https://www.cnblogs.com/xe2011/p/2531643.html
Copyright © 2020-2023  润新知