Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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__

In reply to Re: remove elements win32 gui by kejohm
in thread remove elements win32 gui by teoma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (4)
    As of 2014-09-15 02:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (145 votes), past polls