Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
P is for Practical
 
PerlMonks  

Re: remove elements win32 gui

by kejohm (Hermit)
on Oct 06, 2010 at 07:02 UTC ( #863725=note: print w/ replies, xml ) Need Help??


in reply to remove elements win32 gui

Win32::GUI doesn't allow you to destroy controls yourself, but if you really need to, you can remove the reference to the control from it's parent Window object and any other references to the control, if any. Example:

#!perl use strict; use warnings; use feature qw(:5.12); use Win32::GUI qw(); use Win32::GUI::Constants qw(CW_USEDEFAULT); my $win = Win32::GUI::Window->new( -name => 'win', -text => 'Destroy Window', -size => [ 320, 240 ], -left => CW_USEDEFAULT, ); my $label = $win->AddLabel( -name => 'label', -text => 'Label', -size => [ 80, 25 ], -pos => [ 10, 10 ], ); my $button = $win->AddButton( -name => 'button', -text => 'Remove', -size => [ 80, 25 ], -pos => [ 10, 50 ], -onClick => sub { state $show = 1; if($show){ undef $label; # remove stored reference to cont +rol delete $win->{label}; # remove reference stored in pare +nt window $show = 0; } else { $label = $win->AddLabel( # recreate control -name => 'label', -text => 'Label', -size => [ 80, 25 ], -pos => [ 10, 10 ], ); $show = 1; } return 1; }, ); $win->Show(); Win32::GUI::Dialog(); __END__

This usually isn't the best idea. As mentioned by zentara above, it's usually best to just show and hide the control instead. Example:

#!perl use strict; use warnings; use feature qw(:5.12); use Win32::GUI qw(); use Win32::GUI::Constants qw(CW_USEDEFAULT); my $win = Win32::GUI::Window->new( -name => 'win', -text => 'Destroy Window', -size => [ 320, 240 ], -left => CW_USEDEFAULT, ); my $label = $win->AddLabel( -name => 'label', -text => 'Label', -size => [ 80, 25 ], -pos => [ 10, 10 ], ); my $button = $win->AddButton( -name => 'button', -text => 'Remove', -size => [ 80, 25 ], -pos => [ 10, 50 ], -onClick => sub { if($label->IsVisible()){ $label->Hide(); } else { $label->Show(); } return 1; }, ); $win->Show(); Win32::GUI::Dialog(); __END__


Comment on Re: remove elements win32 gui
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863725]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-04-21 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls