How to add a control in a window at run time using perl win32::GUI?
I have a button control in my window. I need to create a checkbox control in the same window, while I am clicking the button.
I have written the code as mentioned in below, which is not working also.
Please give the correct way to proceed to adding controls at run time using 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();
}
Your problem isn’t the code which adds the control, it’s the fact that the button click event isn’t wired up properly. See the documentation.
Try this instead:
use warnings; 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( -name => "Button1", -text=>"Add Control" ); $win->Show(); Win32::GUI::Dialog(); sub Button1_Click(){ my $mchk=$win->AddCheckbox( -text=>"run_time_con", -pos=>[180,145], ); $mchk->Show(); }