如何使用 perl win32::GUI 创建一个函数来拖动树结构中的节点?

发布于 2024-12-21 05:38:14 字数 2811 浏览 0 评论 0原文

如何使用 perl win32::gui 将一个位置的节点拖放到另一个位置? 是否可以?我正在创建一个树视图并动态添加一个节点。完成树结构后,我需要通过拖动将一个节点位置移动到另一个节点位置。我已经提到了下面的代码。

use strict;
use Win32::GUI;

my $main_window=Win32::GUI::Window->new(
        -name => 'Main',
        -text => 'Main Window',
        -left => 375,
        -top  => 200,
        -width =>510,#370,
        -height =>480,
        -background => [177,175,175],
        -dialogui   => 1,
        -maximizebox => 0,
  );

 $C = new Win32::GUI::Cursor("harrow.cur");

  Win32::GUI::SetCursor($C);

  $B1 = new Win32::GUI::Bitmap("node.bmp");
  $B2 = new Win32::GUI::Bitmap("node_sel.bmp");

    $IL = new Win32::GUI::ImageList(26, 26, 0, 2, 30);
    $IL->Add($B1, 0);
    $IL->Add($B2, 0);

   my $TV=$main_window->AddTreeView(
        -name      => "myTree",
        -text      => "",
        -width     => 220,
        -height    => 238,
        -left      => 260,
        -top       => 198,
        -lines     => 1,
        -rootlines => 1,
        -buttons   => 1,
        -visible   => 1,
        -imagelist => $IL,
        -editlabels =>1,
        -singleexpand => 1,
        -disabledragdrop =>0,

    );
   my $IndentWin = new GUI::Window(
        -text   => "Treeview Indent",
        -name   => "IndentWin",
        -width  => 200,
        -height => 100,
        -left   => 10,
        -top    => 10,
        -background=>[190,190,190],
    );

    my $IndentVal = $IndentWin->AddLabel(
        -text => "Indent value = ".$TV->Indent(),

        -name => "IndentVal",
        -left => 10,
        -top  => 10,
    );

   my $IndentNew = $IndentWin->AddTextfield(
        -text   =>  $TV->Indent(),
        -name   =>  "IndentNew",
        -left   =>  10,
        -top    => 40,
        -width  => 100,
        -height => 25,
    );

   my $IndentSet = $IndentWin->AddButton(
        -text => "Set",
        -name => "IndentSet",
        -left => 130,
        -top  => 10,
    );

  my $Button=$main_window->AddButton(                     
        -text => 'Create tree',
        -name =>  'treecreate',
        -size => [110,20],
        -align=>center,
        -pos  =>  [135,150],
        -font =>  $font1,
        -background =>  [177,175,175],
        -foreground => [],
        -tabstop => 1,
  );

$main_window->Show();

my $DOS = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);
Win32::GUI::Dialog();

sub treecreate_Click{
 for(my $inc=0;$inc>=10;$inc++){
  $TV->InsertItem(
              -text          => 'Root'.$inc,
              -image         => 0,
              -selectedimage => 1,
             );
 }
}

创建树形菜单后,如何将一个节点位置拖放到另一位置。

How to drag and drop a node in one position to another using perl win32::gui?
Is it possible? I am creating a tree view and adding a node by dynamically. After completion of a tree structure I need to move one node position to another by dragging. I have mentioned the code below.

use strict;
use Win32::GUI;

my $main_window=Win32::GUI::Window->new(
        -name => 'Main',
        -text => 'Main Window',
        -left => 375,
        -top  => 200,
        -width =>510,#370,
        -height =>480,
        -background => [177,175,175],
        -dialogui   => 1,
        -maximizebox => 0,
  );

 $C = new Win32::GUI::Cursor("harrow.cur");

  Win32::GUI::SetCursor($C);

  $B1 = new Win32::GUI::Bitmap("node.bmp");
  $B2 = new Win32::GUI::Bitmap("node_sel.bmp");

    $IL = new Win32::GUI::ImageList(26, 26, 0, 2, 30);
    $IL->Add($B1, 0);
    $IL->Add($B2, 0);

   my $TV=$main_window->AddTreeView(
        -name      => "myTree",
        -text      => "",
        -width     => 220,
        -height    => 238,
        -left      => 260,
        -top       => 198,
        -lines     => 1,
        -rootlines => 1,
        -buttons   => 1,
        -visible   => 1,
        -imagelist => $IL,
        -editlabels =>1,
        -singleexpand => 1,
        -disabledragdrop =>0,

    );
   my $IndentWin = new GUI::Window(
        -text   => "Treeview Indent",
        -name   => "IndentWin",
        -width  => 200,
        -height => 100,
        -left   => 10,
        -top    => 10,
        -background=>[190,190,190],
    );

    my $IndentVal = $IndentWin->AddLabel(
        -text => "Indent value = ".$TV->Indent(),

        -name => "IndentVal",
        -left => 10,
        -top  => 10,
    );

   my $IndentNew = $IndentWin->AddTextfield(
        -text   =>  $TV->Indent(),
        -name   =>  "IndentNew",
        -left   =>  10,
        -top    => 40,
        -width  => 100,
        -height => 25,
    );

   my $IndentSet = $IndentWin->AddButton(
        -text => "Set",
        -name => "IndentSet",
        -left => 130,
        -top  => 10,
    );

  my $Button=$main_window->AddButton(                     
        -text => 'Create tree',
        -name =>  'treecreate',
        -size => [110,20],
        -align=>center,
        -pos  =>  [135,150],
        -font =>  $font1,
        -background =>  [177,175,175],
        -foreground => [],
        -tabstop => 1,
  );

$main_window->Show();

my $DOS = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);
Win32::GUI::Dialog();

sub treecreate_Click{
 for(my $inc=0;$inc>=10;$inc++){
  $TV->InsertItem(
              -text          => 'Root'.$inc,
              -image         => 0,
              -selectedimage => 1,
             );
 }
}

after creating tree menu, how to drag and drop the one node position to another position.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2024-12-28 05:38:14

注册一个处理程序来响应树上的 onmousedown onmouseup

当 onmousedown 时,检测哪个项目被选中,然后注册一个响应 onmousemove 的处理程序(闭​​包)

当 onmouseup 时,取消注册响应 onmousemove 的处理程序,检测鼠标位置,如果它仍在树部件上方,则使用 api 调用将先前检测到的项目移动到新位置

您还想在拖动时更改光标

http://cpansearch.perl.org/src/ROBERTMAY /Win32-GUI-1.06/samples/listview_drag_drop.pl

http://search.cpan.org/src/ROBERTMAY/Win32-GUI-1.06/Win32-GUI-DropFiles/t/08_DragQueryPoint.t

Register a handler to respond to onmousedown onmouseup on the tree

when onmousedown, detect which item was selected, then register a handler (closure) that responds to onmousemove

when onmouseup, unregister the handler that responds to onmousemove, detect mouse position, if it was still above tree widget, use api calls to move the previously detected item to new position

you also want to change the curson while dragging

http://cpansearch.perl.org/src/ROBERTMAY/Win32-GUI-1.06/samples/listview_drag_drop.pl

http://search.cpan.org/src/ROBERTMAY/Win32-GUI-1.06/Win32-GUI-DropFiles/t/08_DragQueryPoint.t

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文