两个listbox怎么互相拖动数据(100分)

  • 主题发起人 主题发起人 smilboy
  • 开始时间 开始时间
下面是个简单的例子,可把拖动的内容增加到最后.你可以根据你的情况做修改
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 56
Top = 40
Width = 169
Height = 257
DragMode = dmAutomatic
ItemHeight = 13
TabOrder = 0
OnDragDrop = ListBox1DragDrop
OnDragOver = ListBox1DragOver
end
object ListBox2: TListBox
Left = 288
Top = 40
Width = 233
Height = 257
DragMode = dmAutomatic
ItemHeight = 13
TabOrder = 1
OnDragDrop = ListBox2DragDrop
OnDragOver = ListBox2DragOver
end
end

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
procedure ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source = ListBox1;
end;

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

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if Source=ListBox2 then
ListBox1.Items.Add(ListBox2.Items[ListBox2.ItemIndex]);
end;

procedure TForm1.ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if Source=ListBox1 then
ListBox2.Items.Add(ListBox1.Items[ListBox1.ItemIndex]);
end;

end.
 
接受答案了.
 

Similar threads

后退
顶部