ListView using the mouse to drag up and down movement of the problem. (100 points)

在OnDragDrop事件中處理:
以下是delphi的例子

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);

begin
Accept := Source is TLabel;

end;

This OnDragDrop event handler implements the drop behavior.

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);

begin
if (Sender is TListBox) and (Source is TLabel) then
begin
with Sender as TListBox do
begin
Font := (Source as TLabel).Font;
Color := (Source as TLabel).Color;
end;
end;
end;

 

But if the Drag is set to TRUE
ugly mouse blur will be
how to get rid?

 

The following is LISTBOX1, have about the same, you refer to look at it
to declare more than one form-level variables oldrect: Trect ;, can be added to private following

procedure TForm1.FormDragOver (Sender, Source: TObject ; X, Y: Integer;
State: TDragState; var the Accept: Boolean);
the begin
// FORM acceptable to getting dragged from LISTBOX in operation, a note to leave space outside FORM
IF Source = ListBox1 the then
Accept: = to true;
End;

Procedure TForm1.ListBox1EndDrag (Sender, the target: TObject; X-, the Y: Integer);
the begin
IF (target <> nil) and (target.ClassName <> sender.ClassName) the then
listbox1.Items.Delete (ListBox1.ItemIndex);
IF target the then nil =
listbox1.Canvas.DrawFocusRect (oldrect);
oldrect.Bottom: = 0; // after completion of the drag and drop rectangle variable emptied
End;

Procedure TForm1.ListBox1DragOver (Sender, the Source: TObject; X-, the Y: Integer;
State: TDragState; var the Accept: Boolean);
var
MyPos: the TPoint;
the begin
IF Source = ListBox1 the then
Accept: = to true;
mypos.x: = X;
mypos.y: = Y;
IF listbox1.ItemAtPos (MyPos, to true) < > -1 the then
the begin 
listbox1.Canvas.DrawFocusRect (oldrect); // by 'exclusive or' removing the last frame
listbox1.Canvas.DrawFocusRect (listbox1.ItemRect (listbox1.ItemAtPos (mypos, true))); // Videos the box on the
oldrect: = listbox1.ItemRect (listbox1.ItemAtPos (MyPos, to true));
End;

End;

Procedure TForm1.ListBox1DragDrop (Sender, the Source: TObject; X-, the Y: Integer);
var
P_move: the TPoint;
the begin
{} is obtained by coordinate the ITEM
P_move.x: = X;
p_move.y: = Y;

IF (ListBox1.ItemIndex <> - 1) and (listbox1.ItemAtPos (P_move, to true) <> - 1) the then
// this one can replace that last a few
listbox1.Items.Exchange (listbox1.itemindex, listbox1.ItemAtPos (P_move, true)); // swap ITEM

// drag and drop the following sentence is unsuccessful when you want to get rid of that last picture frame FOCUS
IF listbox1.ItemAtPos (P_move, to true) = - 1 the then
listbox1.Canvas.DrawFocusRect ( oldrect);

Guess you like

Origin www.cnblogs.com/jijm123/p/11106181.html