When trying to programatically limit the number of characters entered 
into a textfield, I learned that you can't use the CHANGE event to do
that since you will be in an endless loop (I guess).  If I used the 
substr() function and then set the text property to this sub string, it 
appeared that the program might be continuing to call the CHANGE
event. This may or not be the case, but it did appear to do some
strange stuff on the screen, then kick me out of the program. 
Since the maxlength property does not exist in Win32-GUI, what
I discovered you can do is give the textfield control a fixed font so
that all characters (A-Z,a-z,0-9, etc.) occupy the same amount of
space in the textfield. Then, so that the cursor does not scroll past
the end of the textfield on the screen, use the 
      -style =>  WS_VISIBLE, WS_TABSTOP
property.  This makes the cursor stop at the end of the textfield 
without scrolling right. You need to use WS_TABSTOP in order
to be able to tab back and forth between other controls even if
you have included the properties -group => 1, -tabstop => 1.
The Courier New font does a good job for this purpose.  The last
step is to then adjust the -width property of the textfield so that
it only allows the maximum number of characters you want entered.

$Font = new Win32::GUI::Font(
    -name => "Courier New",
    -size => 12,
    -weight => 700,
    -height => -14,
);

$BeginDate_l = $W->AddLabel(-name => "BeginDate_1",
                      -text => "BegDt (i.e. yyyymmdd)",
                      -left => 175, 
                      -top => 325, 
                      -height => 18,
                      -align => left,
                      -width => 125 );
$BeginDate = $W->AddTextfield(-name => "BeginDate",
                      -text  => $Today, 
                      -font => $Font,
                      -foreground => 0x8080FF,  
                      -left => 70, 
                      -top => 325, 
                      -style => WS_VISIBLE | WS_TABSTOP, 
                      -group => 1,
                      -tabstop => 1, 
                      -height => 18,
                      -width => 75 );
$BeginDate->SetFocus();
$BeginDate->Select(0,length($BeginDate->Text()));

$EndDate_l = $W->AddLabel(-name => "EndDate_1",
                      -text => "EndDt (i.e. yyyymmdd)",
                      -left => 175, 
                      -top => 350, 
                      -height => 18,
                      -align => left,
                      -width => 125 );
$EndDate = $W->AddTextfield(-name => "EndDate",
                      -text  => $Today, 
                      -font => $Font,
                      -foreground => 0x8080FF,  
                      -left => 70, 
                      -top => 350, 
                      -style => WS_VISIBLE | WS_TABSTOP, 
                      -group => 1,
                      -tabstop => 1, 
                      -height => 18,
                      -width => 75 );

$Shipper_l = $W->AddLabel(-name => "Shipper_1",
                      -text => "Shipper",
                      -left => 175, 
                      -top => 375, 
                      -height => 18,
                      -align => left,
                      -width => 125 );
$Shipper = $W->AddCombobox(-name => "Shipper",
               -font => $Font,
               -foreground => 0x8080FF,
               -left => 70, 
               -top => 375, 
               -group => 1,
               -tabstop => 1, 
               -style => WS_VISIBLE | 3 | WS_VSCROLL | WS_TABSTOP,
               -height => 100,
               -width => 100 );


Regards,
Eric Hansen


Reply via email to