现在实现了两个listbox的相互拖拽 怎么实现禁止他们的自身拖拽? 50分 在线 可行方案 立马给分

genispan 2008-05-11 04:49:54
现在实现了两个listbox的相互拖拽 怎么实现禁止他们的自身拖拽?
...全文
227 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
genispan 2008-05-11
  • 打赏
  • 举报
回复
to GDTOPONE
我拖拽已经实现了
只是要禁止自身拖拽而已
genispan 2008-05-11
  • 打赏
  • 举报
回复
好了 搞定了 给分
GDTOPONE 2008-05-11
  • 打赏
  • 举报
回复
1:将两个Listbox的DragMode属性设为dmAutomatic.

2:在Listbox1的onDragOver事件中写入:

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if Sender is TListBox then
Accept:=true;
end;



3:在Listbox1的onDragDrop事件中写入:

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
TListBox(sender).Items.Add(TListBox(Source).Items[TListBox(Source).itemindex]);
TListBox(Source).Items.Delete(TListBox(Source).itemindex);
end;




4:Listbox2的onDragOver事件指向Listbox1的onDragOver事件,onDragDrop事件指向Listbox1的onDragDrop的事件.
GDTOPONE 2008-05-11
  • 打赏
  • 举报
回复
1:将两个Listbox的DragMode属性设为dmAutomatic.

2:在Listbox1的onDragOver事件中写入:


Delphi(Pascal) code
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if Sender is TListBox then
Accept:=true;
end;




3:在Listbox1的onDragDrop事件中写入:


Delphi(Pascal) code
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
TListBox(sender).Items.Add(TListBox(Source).Items[TListBox(Source).itemindex]);
TListBox(Source).Items.Delete(TListBox(Source).itemindex);
end;




4:Listbox2的onDragOver事件指向Listbox1的onDragOver事件,onDragDrop事件指向Listbox1的onDragDrop的事件.
genispan 2008-05-11
  • 打赏
  • 举报
回复
我明白了 谢谢了 o(∩_∩)o...哈哈
genispan 2008-05-11
  • 打赏
  • 举报
回复
大哥 再帮我下 急啊
genispan 2008-05-11
  • 打赏
  • 举报
回复

if ((Source Is TFileListBox) and (Source <> Sender)) or ((Source Is TDirectoryListBox) and (Source <> Sender)) then
Accept:=True; // accept drag operation

我这样写 还是可以自身拖拽啊
blazingfire 2008-05-11
  • 打赏
  • 举报
回复
在OnDragOver事件中写以上代码
blazingfire 2008-05-11
  • 打赏
  • 举报
回复
Accept := (Source <> Sender) and (Source Is TListBox)

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧