I wasn't able to find any solutions to this in the
archives, but I was able to hack my way through it and
thought I'd share.  

The problem I was having was to use Tab to move
between fields in a window (I usually use a DialogBox,
but wanted a scroll bar - thanks to kenneth for his
great example of doing that).  

I came up with the following (no scroll bars here),
but I feel like it's a hack and there should be a
better way to do it.  But nothing else seemed to work.
 So if anyone has a more elegant solution, please let
me know.


use Win32::GUI;


$AccTable = new Win32::GUI::AcceleratorTable(
                                      "Ctrl-X" => "Close",
                                      "Tab" => "Tab",
                                      "Shift-Tab" => "Shift_Tab",
                                      );

my $window = Win32::GUI::Window 
    -> new (
            -name => 'window',
            -text => "Window",
            -width => 300,
            -height => 200,
            -dialogui => 1,
            -accel => $AccTable,
            );

$t1 = $window
    -> AddTextfield (-name => 't1',
                     -left => 30,
                     -top => 50,
                     -width => 100,
                     -height => 22,
                     -tabstop => 1,
                     -prompt => ["Text 1",50],
                     );

$t2 = $window
    -> AddTextfield (-name => 't2',
                     -left => 30,
                     -top => 100,
                     -width => 100,
                     -height => 22,
                     -tabstop => 1,
                     -prompt => ["Text 2",50],
                     );

my @focuslist = ("t1","t2");

sub Close_Click {
    print "x\n";
    $window -> Hide();
    return -1;
}

sub Tab_Click {
    my $focusat;
     for (my $i=0;$i<=$#focuslist;$i++) {
        if (Win32::GUI::GetFocus() == $window ->
{$focuslist[$i]} -> {-handle}) {
            if ($i < $#focuslist) {
                $focusat = $i+1;
            } else {
                $focusat = 0;
            }
        }
     }
    $window -> {$focuslist[$focusat]} -> SetFocus();
}

sub Shift_Tab_Click {
    my $focusat;
     for (my $i=0;$i<=$#focuslist;$i++) {
        if (Win32::GUI::GetFocus() == $window ->
{$focuslist[$i]} -> {-handle}) {
            if ($i >0) {
                $focusat = $i-1;
            } else {
                $focusat = $#focuslist;
            }
        }
     }
    $window -> {$focuslist[$focusat]} -> SetFocus();
}



$t1 -> SetFocus();


$window -> Show();

sub window_Terminate { -1 }

Win32::GUI::Dialog();







                
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

Reply via email to