博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to Move ListBox Items with the Mouse
阅读量:5135 次
发布时间:2019-06-13

本文共 1435 字,大约阅读时间需要 4 分钟。

The TListBox Delphi component displays a collection of items in a scrollable list. Delphi makes it easy to program into your applications.

Here's how to allow a user to rearrange (change item's position) the items of a ListBox using 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
var
// form level
   StartingPoint : TPoint;
implementation
...
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.ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) ;
begin
   StartingPoint.X := X;
   StartingPoint.Y := Y;
end;
How to Move ListBox Items with the Mouse

转载于:https://www.cnblogs.com/tecsoon/archive/2009/06/04/1496286.html

你可能感兴趣的文章
Date Picker控件:
查看>>
你的第一个Django程序
查看>>
grafana授权公司内部邮箱登录 ldap配置
查看>>
treegrid.bootstrap使用说明
查看>>
[Docker]Docker拉取,上传镜像到Harbor仓库
查看>>
javascript 浏览器类型检测
查看>>
nginx 不带www到www域名的重定向
查看>>
记录:Android中StackOverflow的问题
查看>>
导航,头部,CSS基础
查看>>
[草稿]挂载新硬盘
查看>>
[USACO 2017 Feb Gold] Tutorial
查看>>
关于mysql中GROUP_CONCAT函数的使用
查看>>
OD使用教程20 - 调试篇20
查看>>
Java虚拟机(JVM)默认字符集详解
查看>>
Java Servlet 过滤器与 springmvc 拦截器的区别?
查看>>
(tmp >> 8) & 0xff;
查看>>
linux命令之ifconfig详细解释
查看>>
NAT地址转换
查看>>
Nhibernate 过长的字符串报错 dehydration property
查看>>
Deque - leetcode 【双端队列】
查看>>