listbox的例子如下,分给的太少了
)))
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
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
listbox1.begindrag(false);
end;
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
aPoint:TPoint;
begin
aPoint.x:=x;
aPoint.y:=y;
if (source is tlistbox) and (listbox1.ItemAtPos(apoint,true)<>-1)
and (listbox1.itematpos(apoint,true)<>listbox1.itemindex) then
accept:=true;
end;
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
aPoint:TPoint;
begin
aPoint.x:=x;
aPoint.y:=y;
listbox1.items.Exchange(listbox1.itemindex,listbox1.itematpos(aPoint,true));
end;
end.