I am lost with this simple app, and I hope I am posting to the correct
list; the Sourceforge list appears to dead.

Anyway, the problem is with the event model (I guess). I have 2 fields
and all I want is when the user presses ENTER or TAB in the first field,
I want to capture the text, and have the focus move to the next field. I
have Change set for the fields, which is alright, but I fail to see how
I can capture the RETURN or TAB key. Annoyingly, the LostFocus event
fires every time a key is pressed, which makes no sense to me.

Below is my simplified code which displays the action. I'm sorry that it
is about 90 lines in length. Can anyone help?

Thank you,

Barry Brevik
---------------------------
use strict;
use warnings;
use Win32;
use Win32::GUI();

my $main = Win32::GUI::Window -> new
(
  -name   => 'Main',
  -title  => 'Test v0.1',
  -width  => 400,
  -height => 200
);

my $monoinput = Win32::GUI::Font -> new(-name => 'Consolas', -size =>
10, -bold => 0, -italic => 0);
my $monolabel = Win32::GUI::Font -> new(-name => 'Consolas', -size =>
10, -bold => 1, -italic => 0);

my $userlabel = $main -> AddLabel
(
  -font => $monolabel,
  -pos  => [10, 22],
  -text => 'username:',
  -foreground => 0xff4444
);

# Create a text input field.
my $userfield = $main -> AddTextfield
(
  -eventmodel   => "byname",
  -name         => "username",
  -align        => "left",
  -tabstop      => 1,
  -pos          => [76, 20],
  -size         => [100, 24],
  -width        => 100,
  -height       => 20,
  -password     => 0,
  -passwordChar => chr(249),
  -background   => 0xffffff,
  -font         => $monoinput,
  -text         => '',
  -dialogui => 1      # Enable keyboard navigation like DialogBox
);

my $passlabel = $main -> AddLabel
(
  -font => $monolabel,
  -pos  => [10, 64],
  -text => 'password:',
  -foreground => 0xff4444
);

# Create a text input field.
my $passfield = $main -> AddTextfield
(
  -eventmodel   => "byname",
  -name         => "password",
  -align        => "left",
  -tabstop      => 1,
  -pos          => [76, 60],
  -size         => [100, 24],
  -password     => 1,
  -passwordChar => chr(249),
  -background   => 0xffffff,
  -font         => $monoinput,
  -text         => '',
  -dialogui => 1      # Enable keyboard navigation like DialogBox
);

$userfield -> MaxLength(16);
$passfield -> MaxLength(16);

$main -> username -> SetFocus();
$main -> Show();
Win32::GUI::Dialog();

exit(0);

#----------------------------------------------------------
sub username_Change
{
  Win32::MsgBox("Username field has changed", 48, "Message from
Username");
  $userfield -> SetFocus();
}

#----------------------------------------------------------
sub username_LostFocus
{
  Win32::MsgBox("Username field has lost focus", 48, "Message from
Password");
}

#----------------------------------------------------------
sub Main_Terminate {-1;}

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to