Hi,

The example below will only work on the latest code line from CVS. 

I'm trying to get my head round using scroll bars. In my test example I want to 
create a window containing one tab strip. In the tab strip there will be a 
child window containing a scroll bar and 10 buttons. Scrolling the scroll bar 
will move the buttons into and out view.

Now, the scrolling part works fine - but is using a child window in this way 
the correct approach? For example, interacting with the child window (clicking 
on a button, or scrolling) loses focus (which you would expect for a normal 
window) but is not the correct behaviour in this case. Am I missing something 
fundamental?

Apologies for the dodgy code - is a hack job:)

cheers,

jez.

===========
use Win32::GUI;
use Win32::GUI::BorderlessWindow;

#create the main window
my $win = new Win32::GUI::Window (
 -name => "MainWin",
 -left => 0,
 -top => 100,
 -width => 500,
 -height => 300,
 -sizable => 1,
 -text => "Scrollbar Test 2",
 -noflicker => 1,
);

#create a tab strip
$win->AddTabStrip (
 -name => "Tab",
 -left => 0,
 -top => 100,
 -width => 250,
 -height => 150,  
);
$win->Tab->InsertItem(-text => 'Some Tab');

#create a child window with a scroll bar
my $childwin = new Win32::GUI::BorderlessWindow (
 -name => "Child",
 -parent =>$win,
 -left => 10,
 -top => 250,
 -width => 200,
 -height => 120,
 -hscroll => 1,
 -noflicker => 1,
 -onScroll => \&scrolled
);

#create content for our child window, 10 buttons.
foreach (0..9) {
  $childwin->AddButton (
           -name     => "Button".$_,
           -pos      => [$_*50, 30],
           -size     => [50, 20],
           -text     => 'Button'.$_,);
}

#set the scrollbar range and starting pos
$childwin->ScrollRange(0,0,450);
$childwin->ScrollPos(0,0);

$win->Show;
$childwin->Show;
Win32::GUI::Dialog;

sub scrolled {
 my($object,$bar,$operation,$pos) = @_;
 my $string;
 $object->Scroll($bar,$operation,$pos);
 #Scroll the buttons...
 if($operation == SB_THUMBTRACK) {
    foreach (0..9) {
      $string='Button'.$_;
      $childwin->$string->Move(($_*50)-$pos,30);
    }
  }
}

Reply via email to