I
import
Unregistered / Unconfirmed
GUEST, unregistred user!
我想作一个类似文件管理器的界面,左边是treeview右边是listview如何实现从右边拖一个东东到左边的treeview中???如何得知用户将东东放在了treeview的哪个item中,以及用户拖来的是listview中的哪个项?
最好能给出简单例程!
//如下:
implementation
{$R *.DFM}
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
Listbox1.DragMode := dmManual;
Listbox1.BeginDrag(False,-1);
end;
end;
procedure TForm1.Label1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if (Sender is TLabel) and (Source is TListBox) then
begin
with Sender as Tlabel do
begin
Font := (Source as Tlistbox).Font;
Color := (Source as TlistBox).Color;
Caption := (Source as TlistBox).Items[(Source as TlistBox).ItemIndex]
end;
end;
end;
procedure TForm1.Label1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TLIstBox;
end;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TLIstBox;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
With (Sender as TTreeView) do
begin
GetNodeAt(X,Y).Text := (Source as TListBox).Items[(Source as TlistBox).ItemIndex];
end;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
With (Sender as TTreeView) do
begin
ItemS.AddChild (GetNodeAt(X,Y),(Source as TListBox).Items[(Source as TlistBox).ItemIndex]);
end;
最好能给出简单例程!
//如下:
implementation
{$R *.DFM}
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
Listbox1.DragMode := dmManual;
Listbox1.BeginDrag(False,-1);
end;
end;
procedure TForm1.Label1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if (Sender is TLabel) and (Source is TListBox) then
begin
with Sender as Tlabel do
begin
Font := (Source as Tlistbox).Font;
Color := (Source as TlistBox).Color;
Caption := (Source as TlistBox).Items[(Source as TlistBox).ItemIndex]
end;
end;
end;
procedure TForm1.Label1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TLIstBox;
end;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TLIstBox;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
With (Sender as TTreeView) do
begin
GetNodeAt(X,Y).Text := (Source as TListBox).Items[(Source as TlistBox).ItemIndex];
end;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
With (Sender as TTreeView) do
begin
ItemS.AddChild (GetNodeAt(X,Y),(Source as TListBox).Items[(Source as TlistBox).ItemIndex]);
end;