【问题标题】:Adding controls at run time using perl win32::gui使用 perl win32::gui 在运行时添加控件
【发布时间】:2011-12-02 20:52:46
【问题描述】:

如何在运行时使用 perl win32::GUI 在窗口中添加控件? 我的窗口中有一个按钮控件。在单击按钮时,我需要在同一窗口中创建一个复选框控件。 我已经编写了如下所述的代码,它也不起作用。 请给出在运行时使用 perl Win32::GUI 添加控件的正确方法

use strict;
use Win32;
use Win32::GUI;

my $win=Win32::GUI::Window->new(
        -name => 'wino',
        -text => 'window',
        -left => 375,
        -top  => 400,
        -width =>380,
        -height =>260,
);
my $but=$win->AddButton(
      -text=>"Add Control",
      -onclick=>\&add_control,
);

 $win->Show();
 Win32::GUI::Dialog();

 sub add_control(){

   my $mchk=$win->AddCheckbox(
    -text=>"run_time_con",
    -pos=>[180,145],
   );

   $mchk->Show();

 }

【问题讨论】:

    标签: perl


    【解决方案1】:

    您的问题不是添加控件的代码,而是按钮单击事件未正确连接的事实。请参阅documentation

    试试这个:

    使用警告; 使用严格; 使用Win32; 使用 Win32::GUI(); 我的 $win=Win32::GUI::Window->new( -name => 'wino', -text => '窗口', -左 => 375, -顶部 => 400, -宽度=> 380, -高度 => 260, ); 我的 $but=$win->AddButton( -name => "Button1", -text=>“添加控制” ); $win->显示(); Win32::GUI::Dialog(); 子 Button1_Click(){ 我的 $mchk=$win->AddCheckbox( -text=>"run_time_con", -pos=>[180,145], ); $mchk->显示(); }

    【讨论】:

    • 是的,刚才我注意到了。谢谢... :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多