鼠标拖放插入点提示
鼠标拖放是Windows常见的操作,比如拷贝文件就可用拖放方式进行。在我们编写的应用程序中,有时为了方便用户操作需要支持鼠标拖放。对于大部分的VCL控件只要鼠标将DragMode设为dmAutomatic,就可以在OnDragDrop、OnDragOver和OnEndDrag中处理拖放事件。与Drag类似的还有一个Dock方式用于支持控件悬浮,控件在悬浮时会显示一个虚线框来表示悬浮位置,而Drag方式却没有这功能。现在让我们尝试在Listbox中显示拖放插入点。上面提及的三个事件中OnDragOver是用来拖放鼠标经过控件上面时产生的,要显示插入点提示当然是在这里进行处理了。事件中先用Listbox.ItemAtPos(Point(X, Y) , true)取鼠标所有在的打目Index,再用Listbox.ItemRect(Index)取得作图区域,最后在区域中画出提示线框。下面给出代码:
Unit1.pas内容 unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
private
FDragOverObject: TObject; //ListBox1DragDrop、ListBox1DragOver由多个Listbox共享,这里记录当前那个Listbox接受鼠标拖放
FDragOverItemIndex: Integer; //记录鼠标所在条目的Index
procedure DrawInsertLine;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{========================================================================
DESIGN BY : 彭国辉
DATE: 2004-12-24
SITE: http://kacarton.yeah.net/
BLOG: http://blog.csdn.net/nhconch
EMAIL: kacarton#sohu.com
文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
=========================================================================}
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
i: integer;
begin
//拖放完成,将内容从原来的Listbox读到目标Listbox
with TListBox(Source) do begin
i := TListBox(Sender).ItemAtPos(Point(X, Y) , true);
if i<>-1 then
TListBox(Sender).Items.InsertObject(i, Items[ItemIndex], Items.Objects[ItemIndex])
else
i := TListBox(Sender).Items.AddObject(Items[ItemIndex], Items.Objects[ItemIndex]);
if (Sender=Source) and (i>ItemIndex) then i := i-1;
DeleteSelected;
if (Sender=Source) then ItemIndex := i;
end;
FDragOverObject := nil;
FDragOverItemIndex := -1;
end;
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
Index: Integer;
begin
Accept := (Source is TListBox) and (TListBox(Source).ItemIndex>-1); //只接受来自Listbox的内容
if not Accept then Exit;
if (FDragOverObject<>nil) and (Sender<>FDragOverObject) then
DrawInsertLine; //鼠标离开Listbox时,擦除插入位置提示线框
Index := TListBox(Sender).ItemAtPos(Point(X, Y) , true);
if (FDragOverObject = Sender) and (FDragOverItemIndex = Index) then Exit; //当鼠标在同一条目上移动时,只画一次即可
if (FDragOverObject = Sender) and (FDragOverItemIndex <> Index) then
DrawInsertLine; //鼠标移到新位置,擦除旧的插入位置提示线框
FDragOverObject := Sender;
FDragOverItemIndex := Index;
DrawInsertLine; //画出插入位置提示线框
end;
procedure TForm1.DrawInsertLine;
var
R: TRect;
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
- AnsiString?PChar?赋值
- Report Machine 3.0 (报表
- MapX v5.02.25 破解文件
- WDBOX v1.0 多选下拉列表
- 用Delphi开发视频聊天软件
- Delphi客户服务器应用开发
- AES 加密算法函数包及演示
- ACCESS/SQL 数据库存取图
- 熊猫烧香核心源码(Delphi
- 把整个网页保存成JPG图片(
- 高级计算器 V1.0 (含代码)
- Delphi版模仿熊猫烧香病毒
- 精确定位打印程序 (含源代
- Delphi文件管理(六)
- 将数字四舍五入保留两位小
- 绝地程序编辑器 v1.0.1.4
- 关于自定义界面的方案(Eas
- Delphi 对象链接与嵌入(
- 用HTML页面做程序界面演示
- Delphi模拟最小化恢复关闭
- 用Delphi实现24位真彩色图
- 限制客户机运行程序 (有关
- Delphi中用API实现在MSN的
- DELPHI数据库应用程序的开
- Delphi 动态链接库编程(
- QQ号码自动申请器及源代码
- Win9x 下调整系统时钟控件
- delphi中的XML解析控件TXM
- 几个游戏内存修改器代码
- TT8 DevExpress 最新系列
- Tnt Delphi Unicode Contr
- DelphiTwain 2004-1-20 (
- Delphi中数据的自动录入
- 经验技巧:分享两条Delphi
- Delphi中Hash表的使用方法
网站运营 建站经验 策划盈利 搜索优化 网站推广 免费资源
网站联盟 联盟新闻 联盟介绍 联盟点评 网赚技巧
行业资讯 业界动态 搜索引擎 网络游戏 门户动态 电子商务 广告传媒
网络编程 Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术 Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷 Internet Explorer
网页制作 FrontPages Dreamweaver Javascript css photoshop fireworks Flash
程序设计 Java技术 C/C++ VB delphi
网络知识 网络协议 网络安全 网络管理 组网方案 Cisco技术
操作系统 Win2000 WinXP Win2003 Mac OS Linux FreeBSD



