2008/4/30 Steven Vasilogianis <[EMAIL PROTECTED]>:
> I have been having some trouble getting my scroll bars to work well. I
>  have been modifying an example I found on Rob May's weblog
>  (http://blog.robmay.me.uk/search/label/perl-win32-gui).
>
>  Sample code is included below. The problems I am having are:
>
>  1) The ScrollRange() call does not seem to be doing anything - I can
>  scroll well beyond the range specified.

I don't think you can really.

>  2) SB_PAGE(UP|DOWN) events are not working at all

Because you never set the page size.

>  I am rather new to Win32::GUI and would appreciate any help.

Here's a minimally adapted version of your code that works for me.
There are easier ways to do this, and you really need to see the next
few examples in the series of scrollbar articles - I wrote the code at
the same time as the first 7 articles, but haven't had time to turn
them into full articles yet.  I will post to this list when I do.

Regards,
Rob.

#!perl -w
use strict;
use warnings;

use Win32::GUI 1.05 qw(
   SB_VERT SB_LINEUP SB_LINEDOWN SB_PAGEUP SB_PAGEDOWN
   SB_THUMBTRACK SB_THUMBPOSITION
);

my $window = Win32::GUI::DialogBox->new(
   -name => "scroll_test",
   -text => "Scroll Test",
   -size => [400, 400],
   -vscroll => 1,
   -onScroll => \&process_scroll,
);

my $v_pos = 5;
for ( 1..100 ) {
   $window->AddLabel(
       -name => "label$_",
       -text => "Label $_",
       -pos => [5, $v_pos],
       -size => [100, 30],
   );

   $v_pos += 35;
}

$window->ScrollRange(SB_VERT, 0, 5 + (35 * 99) + $window->label1->Height());
$window->ScrollPage(SB_VERT, $window->ScaleHeight());

$window->Show();
Win32::GUI::Dialog();

sub process_scroll {
   my ( $self, $bar, $op, $pos ) = @_;

   my $prev_pos = $self->ScrollPos($bar);
   my $new_pos  = $prev_pos;

   if ( $op == SB_LINEUP ) {    # or SB_LINELEFT
       $new_pos -= 35;
   } elsif ( $op == SB_LINEDOWN ) {    # or SB_LINERIGHT
       $new_pos += 35;
   } elsif ( $op == SB_PAGEUP ) {      # or SB_PAGELEFT
       $new_pos -= $self->ScrollPage($bar);
   } elsif ( $op == SB_PAGEDOWN ) {    # or SB_PAGERIGHT
       $new_pos += $self->ScrollPage($bar);
   } elsif ( $op == SB_THUMBTRACK ) {
       $new_pos = $pos;
   } elsif ( $op == SB_THUMBPOSITION ) {
       $new_pos = $pos;
   }

   $new_pos = $self->ScrollPos( $bar, $new_pos );
   print "NP: $new_pos\n";

   if ( $bar == SB_VERT ) {
        my $v_pos = 5;
        for ( 1..100 ) {
           $self->{"label$_"}->Top($v_pos - $new_pos);

           $v_pos += 35;
        }
   }
   $self->Redraw(1);

   1;
}
__END__

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to