是两个LISTBOX中的ITEMS的拖动吗?这是很典型的例子,先把要使用(拖操作)的LISTBOX的DRAGMODE设成dmAutomatic,
然后剩下的工作就不多了,然后在目标LISTBOX(放操作)的DragOver事件中将ACCEPT参数设为TRUE(最好判断一下拖放源)。这样才能允许对象在目标LISTBOX中放下。然后将要处理的一些代码写在目标LISTBOX的DragDrop事件中。
这样整个操作就完成了。当然也可以手工控制拖放操作:将LISTBOX的DRAGMODE设成dmManual,然后在源LISTBOX(拖操作)的MOUSEDOWN事件中写下:LISTBOX1.BEGINDRAG(TRUE),参数设为TRUE,FALSE是控制鼠标指针的变化时限,准确说是控制拖放操作的开始。
给你个例子如下:(两个Tlistbox名叫:lbx1,lbx2)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
lbx1: TListBox;
lbx2: TListBox;
procedure lbx2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure lbx2DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure lbx1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure lbx1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.lbx2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if source=lbx1 then //如果源对象是LBX1
accept:=true;
end;
procedure TForm1.lbx1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if source=lbx2 then //如果源对象是LBX2
accept:=true;
end;
procedure TForm1.lbx2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
lbx2.Items.Add(lbx1.Items.Strings[lbx1.ItemIndex]); //实现拖放操作的结果,ITEM的增减
lbx1.Items.Delete(lbx1.ItemIndex);
end;
procedure TForm1.lbx1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
lbx1.Items.Add(lbx2.Items.Strings[lbx2.ItemIndex]); //实现拖放操作的结果,ITEM的增减
lbx2.Items.Delete(lbx2.ItemIndex);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
//给两个LISTBOX加上几个条目以供演示
for i:=0 to 5 do
begin
lbx1.Items.Add(inttostr(i));
lbx2.Items.Add(inttostr(i));
end;
end;
end.