perl win32::gui remove elements
I have a dialogbox, to which i populate elements(labels) on activate event. I want to remove these elements(labels) when the window is being deactivated. something like:[its erroneous fragment of main code but explanatory]
my $wchRW = Win32::GUI::DialogBox->new(
-name => "wchR",
-title => "whed",
-left => CW_USEDEFAULT,
-size => [300, 130],
-parent => $mw,
);
$wchRW->AddGroupbox(
-name => "wchR_gb",
-text => "being watched",
-width => $wchRW->ScaleWidth() - $padding,
-height => 100,
-left => $padding/2,
);
sub wchR_Activate {
my $wchtxt = "sample";
# lbleft, lbtop are calculated here
$wchRW->AddLabel(
-name => "wchR_lb0",
-text => $wchTxt,
-left => $lbLeft,
-top => $lbTop,
);
}
sub gitni_wchR_Deactivate {
print "Here\n";
Win32::GUI::DestroyWindow($wchRW->wchR_lb0); #this is line n
}
#i have a button in main window $mw.
#onclick 开发者_运维百科of this button this dialogbox is shown.
#sub b1_Click { $wchRW->DoModal(); return 0; }
But the problem is, "Here" in deactivate is called many times and an exception is thrown thereafter [can't locate auto/wchR_.al in @INC .... line n]. Freezing the main window and only option is to end process through task-manager.
Please help me out. Why "here" is printed many times? How to remove element permanently? Thanks
The sub wchR_Deactivate
will be invoked many times because it happens every time when dialog lost focus.
Normally you should not do AddLabel
in _Activeate() event handler. All the thing should be created ahead. You could do Win32::GUI::Hide
or Win32::GUI::Show
to manipulate the control display status, and using $wchRW->wchR_lb0->Text($new_message)
to change the message.
精彩评论