Thank you both Jason and Robert,

Your answers are fully satisfy for me! 
Great Thanks for them (and for very short time of your responses).

to Robert:
Thank you for your other remarks about programming. I'm accepting them.

Waldemar


Dnia wtorek, 13 czerwca 2006 23:41, napisałeś:
> Jason P wrote:
> > Waldemar Biernacki wrote:
> >> Hello!
> >>
> >> I've got the following code (at the end if the mail). Here I've got two
> >> buttons: one to change label's text and other to change its visibility.
> >> The text flip button works fine, whereas that connected with visibility
> >> doesn't.
>
> Thanks for an excellent, short, complete bit of code :-)
>
> > I believe "-visibility" is supposed to be "-visible"
>
> Yes indeed it is, but that doesn't get you all the way there: all
>     $win->Change(-visible => $x)
> does is set or unset the WS_VISIBLE style -> You still need a call to
> Show() to get the window to redraw correctly.
>
> Try it:  When you toggle the window state, you'll see no change unless
> you do something to get the window to redraw (for example minimise it
> and then restore the window)
>
> Is this a bug with Win32::GUI?  Probably, as it's not doing what you
> would expect,  but as Jason points out there are alternative ways.
>
> >  but consider the following
> > $lbl->IsVisible() ? $lbl->Hide() : $lbl->Show();
>
> even easier:
>    $label->Show($state);  # $state =0 (SW_HIDE) or 1 (SW_SHOWNORMAL)
>
>
>
>
> A couple of style pointers:
> (1) Unless you want lots of constants exported into you namespace, then
>      use Win32::GUI();
> rather than
>      use Win32::GUI;
> As of the next release the latter form will elicit warnings.
>
> (2) You don't need the evals in this case - they add overhead, and hide
> errors until runtime.
>
> This is how my code might look:
>
> #!perl -w
> use strict;
> use warnings;
>
> use Win32::GUI();
>
> my $state=1;
>
> my $frame = Win32::GUI::Window->new(
>      -size => [200,200],
> );
>
> my $label = $frame->AddLabel(
>      -text => $state,
>      -pos  => [110,70],
>      -size => [50,50],
> );
>
> $frame->AddButton(
>      -text    => 'visibility flip button',
>      -pos     => [10,20],
>      -onClick => sub{
>          $state=1-$state;
>          $label->Show($state);
>      },
> );
>
> $frame->AddButton(
>      -name    => 'button2',
>      -text    => 'text flip button',
>      -pos     => [10,120],
>      -onClick => sub{
>          $state=1-$state;
>          $label->Text($state);
>      },
> );
>
> $frame->Show();
> Win32::GUI::Dialog();
> $frame->Hide();
> exit(0);
> __END__
>
> Regards,
> Rob.

Reply via email to