首页 > 代码库 > TreeView节点拖拉操作1
TreeView节点拖拉操作1
TreeView节点拖拉操作1
//事先设置 TreeView1.DragMode= dmAutomatic;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//var
// node:TTreeNode;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
// node := TreeView1.GetNodeAt(X, Y);
// Caption:=node.Text;
Accept := Source = Sender;
if not Accept then exit;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
with TreeView1 do
// node:TTreeNode;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
// node := TreeView1.GetNodeAt(X, Y);
// Caption:=node.Text;
Accept := Source = Sender;
if not Accept then exit;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
with TreeView1 do
begin
if (Sender <> Source) then exit;
if (DropTarget = nil) then exit;
if (DropTarget = Selected) then exit;
Selected.MoveTo(DropTarget,naAddChildFirst);
end;
end;
end.
if (Sender <> Source) then exit;
if (DropTarget = nil) then exit;
if (DropTarget = Selected) then exit;
Selected.MoveTo(DropTarget,naAddChildFirst);
end;
end;
end.
TNodeState = (nsCut, nsDropHilited, nsFocused, nsSelected, nsExpanded);
TNodeAttachMode = (naAdd, naAddFirst, naAddChild, naAddChildFirst, naInsert);
TAddMode = (taAddFirst, taAdd, taInsert);
拖拽时可以看见拖拽的图标如果有的话
来自为知笔记(Wiz)
附件列表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。