Self-tow and mutual drag in ListBox multi-select

zhaozj2021-02-17  73

Unit unit1;

File: // lei: e_mail yanleiigis@21cn.com

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;

type TForm1 = class (TForm) ListBox1: TListBox; ListBox2: TListBox; procedure ListBox1DragDrop (Sender, Source: TObject; X, Y: Integer); procedure ListBox1DragOver (Sender, Source: TObject; X, Y: Integer; State: TDragState; VAR accept: boolean; procedure formcreate (sender: TOBJECT); private {private declarations}

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TForm1.ListBox1dragover (Sender, Source: Tobject; x, y: integer; state: tdragState; var apoint: tpoint; begin apoint.x: = x; apoint.y: = y;

IF (Source As TListBox) .Selcount> 0) AND (Sender As TListbox) .Itemtpos (Apoint, True) <> -1) and (Sender as TListbox) .Ittpos (Apoint, True) <> (sender as tlistbox) .ItemIndex) .In, an;

Procedure TForm1.ListBox1dragdrop (Sender, Source: Tobject; x, y: integer; var apoint: tpoint; st: string; p: integer; i, num: integer; melbox: tstrings; begin apoint.x: = x; apoint .y: = y;

P: = (Sender as tlistbox) .Itemtpos (apoint, true);

MYLBOX: = TSTRINGLIST.CREATE; TRY NUM: = (Source As TListBox) .Items.count; for i: = Num - 1 Downto 0 Do Begin IF (Source As TListBox) .Selected [i] The begin St: = (Source as tlistbox) .Ilbox.add (st)

End; end; if p> -1 the begin for i: = 0 to mylbox.count - 1 do begin (sender as tlistbox) .Items.insert (p, mylbox [i])

End; ELSE BEGIN for i: = MYLBOX.COUNT - 1 Downto 0 Do Begin (Sender As Tlistbox) .Ilbox [i])

END;

End; (Source as TListBox) .deleteselected; if p> -1 the (sender as teistbox) .selected [P]: = true; finally mylbox.free;

END;

procedure TForm1.FormCreate (Sender: TObject); begin listbox2.OnDragDrop: = listbox1.OnDragDrop; listbox2.OnDragOver: = listbox1.OnDragOver; listbox1.MultiSelect: = true; listbox2.MultiSelect: = true; listbox1.DragMode: = dmAutomatic; Listbox2.dragmode: = DMautomatic;

END;

End.

转载请注明原文地址:https://www.9cbs.com/read-31385.html

New Post(0)