鼠标拖动 都是激发DragOver事件和DragDrop事件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit UnitListBoxDrag;//用鼠标拖动对LISTBOX中的ITEM直接上移;或下移interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) ListBox1: TListBox; //DragMode:=dmManual procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin if Button = mbLeft then with Sender as TListBox do begin if ItemAtPos(Point(X, Y), True) >= 0 then //保证ListBox1DragDrop中nS>=0 BeginDrag(False); //允许ListBox单独处理鼠标事件而并不开始拖动 end;end;procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);begin Accept:=false; if (Source is TListBox) and (TListBox(sender).ItemAtPos(Point(X, Y), True) >= 0) then Accept := True; //保证ListBox1DragDrop中nD>=0end;procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);var sTemp:String; nS,nD:integer;begin nS:=ListBox1.ItemIndex; //当前列表项索引号(拖放的源地址) nD:=ListBox1.ItemAtPos(Point(X, Y), True); //目的索引号 sTemp:=ListBox1.Items[nS];//储存源项 ListBox1.Items[nS]:=ListBox1.Items[nD];//交换源,目的项值 ListBox1.Items[nD]:=sTemp;end;end. 关于VB的 Activex dll 求一个可用的DELPHI7的注册机 关于元件的问题,请各位关注一下,谢谢!!! delphi6.0的画图问题? 关于“数据库”中图片的问题? 请ljmanage兄来接分! :)... 请问在Dephi 6.0中哪个组件可以打开html、htm、txt等格式文件? 我的程序把数据集另存为Excel时,导出43条的数据竟要30秒,请各位帮俺出出主意,如何提高导出效率? 如何通过猫给手机发短消息? 从哪儿能够找到关于Delphi多线程变量互斥/共享访问的资料? 锁定 DBGrid 左边几列不移动 请问如何发布三层MIDAS程序在广域网上?急需。。在线等待
//用鼠标拖动对LISTBOX中的ITEM直接上移;或下移
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox; //DragMode:=dmManual
procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
with Sender as TListBox do
begin
if ItemAtPos(Point(X, Y), True) >= 0 then //保证ListBox1DragDrop中nS>=0
BeginDrag(False); //允许ListBox单独处理鼠标事件而并不开始拖动
end;
end;procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:=false;
if (Source is TListBox) and (TListBox(sender).ItemAtPos(Point(X, Y), True) >= 0) then
Accept := True; //保证ListBox1DragDrop中nD>=0
end;procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
sTemp:String;
nS,nD:integer;
begin
nS:=ListBox1.ItemIndex; //当前列表项索引号(拖放的源地址)
nD:=ListBox1.ItemAtPos(Point(X, Y), True); //目的索引号
sTemp:=ListBox1.Items[nS];//储存源项
ListBox1.Items[nS]:=ListBox1.Items[nD];//交换源,目的项值
ListBox1.Items[nD]:=sTemp;
end;
end.