【问题标题】:perl win32::gui remove elementsperl win32::gui 删除元素
【发布时间】:2010-10-05 12:44:38
【问题描述】:

我有一个对话框,我在激活事件时填充元素(标签)。 我想在停用窗口时删除这些元素(标签)。类似于:[其错误的主要代码片段,但可以解释]

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; }

但问题是,deactivate 中的 "Here" 被调用了很多次,然后抛出异常 [can't locate auto/wchR_.al in @INC .... line n]。冻结主窗口,唯一的选择是通过任务管理器结束进程。

请帮帮我。 为什么“这里”被打印了很多次? 如何永久删除元素? 谢谢

【问题讨论】:

    标签: perl user-interface winapi win32gui


    【解决方案1】:

    sub wchR_Deactivate 将被多次调用,因为每次对话框失去焦点时都会发生这种情况。

    通常你不应该在 _Activeate() 事件处理程序中执行AddLabel。所有的东西都应该提前创建。您可以使用Win32::GUI::HideWin32::GUI::Show 来操作控件显示状态,并使用$wchRW->wchR_lb0->Text($new_message) 来更改消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 2013-12-10
      相关资源
      最近更新 更多