![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Перетаскивание в ListBox [D7, XP]
Blari © (2006-05-30 22:42:00)Подскажите пожалуйста как в ListBox перетаскивать элименты (менять местами) при помощи мыши. Или дайте ссылку на пример.
MBo (2006-05-31 07:07:00) [1]http://www.delphimaster.ru/articles/dragndrop/index.html
antonn (2006-05-31 07:07:00) [2]
var IsMouseDown:boolean;
nusel:integer;
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsMouseDown:=true;
nusel:= Listbox1.ItemIndex;
end;
procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsMouseDown:=false;
end;
procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
var old:integer;
begin
if IsMouseDown then begin
old:= listbox1.ItemIndex;
if nusel >=ListBox1.Items.Count-1 then nusel:=ListBox1.Items.Count-1 else
if nusel <=0 then nusel:=0 ;
if old >=ListBox1.Items.Count-1 then old:=ListBox1.Items.Count-1 else
if old <=0 then old:=0;
ListBox1.Items.Move(nusel,old);
nusel:= old ;
end;
end;
Gydvin (2006-05-30 22:58:00) [3]Быстренько накидал
Можно например так, только это надо доробатывать
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
string1:integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i:integer;
s:string;
begin
if string1=-1 then exit;
i:=listbox1.ItemIndex;
if i=-1 then exit;
s:=listbox1.Items.Strings[string1];
listbox1.Items.Insert(i,s);
if i<string1 then inc(string1);
listbox1.Items.Delete(string1);
listbox1.ItemIndex:=i;
string1:=-1;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
string1:=-1;
end;
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i:integer;
begin
string1:=-1;
i:=listbox1.ItemIndex;
if i=-1 then exit;
string1:=i;
end;
end.