var
Value: String;//全局变量
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyPoint: TPoint;
begin
if Button = mbLeft then
begin
MyPoint.X := X;
MyPoint.Y := Y;
Value := ListBox1.Items[ListBox1.ItemAtPos(MyPoint, True)];
//ListBox1.Items.Delete(ListBox1.ItemAtPos(MyPoint, True));
Screen.Cursor := crDrag;
end;
end;procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyPoint: TPoint;
begin
if Button = mbLeft then
begin
MyPoint.X := X;
MyPoint.Y := Y;
ListBox1.Items.Delete(ListBox1.Items.IndexOf(Value));
ListBox1.Items.Insert(ListBox1.ItemAtPos(MyPoint, True), Value);
Screen.Cursor := crDefault;
end;
end;
Value: String;//全局变量
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyPoint: TPoint;
begin
if Button = mbLeft then
begin
MyPoint.X := X;
MyPoint.Y := Y;
Value := ListBox1.Items[ListBox1.ItemAtPos(MyPoint, True)];
//ListBox1.Items.Delete(ListBox1.ItemAtPos(MyPoint, True));
Screen.Cursor := crDrag;
end;
end;procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyPoint: TPoint;
begin
if Button = mbLeft then
begin
MyPoint.X := X;
MyPoint.Y := Y;
ListBox1.Items.Delete(ListBox1.Items.IndexOf(Value));
ListBox1.Items.Insert(ListBox1.ItemAtPos(MyPoint, True), Value);
Screen.Cursor := crDefault;
end;
end;
Value: String;//全局变量
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyPoint: TPoint;
begin
if Button = mbLeft then
begin
MyPoint.X := X;
MyPoint.Y := Y;
Value := ListBox1.Items[ListBox1.ItemAtPos(MyPoint, True)];
//ListBox1.Items.Delete(ListBox1.ItemAtPos(MyPoint, True));
Screen.Cursor := crDrag;
end;
end;procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyPoint: TPoint;
begin
if Button = mbLeft then
begin
MyPoint.X := X;
MyPoint.Y := Y;
ListBox1.Items.Delete(ListBox1.Items.IndexOf(Value));
ListBox1.Items.Insert(ListBox1.ItemAtPos(MyPoint, True), Value);
Screen.Cursor := crDefault;
end;
end;
State: TDragState; var Accept: Boolean);
begin
accept:=true;
end;procedure TForm1.ListBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
var
buf:string;
begin
if (x=0)or(y=0) then exit;
with tlistbox(sender) do
begin
buf:=items[itemindex];
items.Delete(itemindex);
items.Insert(itematpos(point(x,y),true),buf);
end;
end;//dragmode设为dmautomatic