You need an event handler to handle the Click event on your "OK" button (you
may know that, but JIC). The name of the subroutine would need to be then
name of your "OK" button followed by _Click. Additionally, you must have
either:
        -multisel               =>      1,
        
or

        -multisel               =>      2,

in the listbox definition to allow for selection of multiple items from that
listbox.

You need to use two functions: SelectedItems (returns a 0 based list of all
items selected in the list box).  When you have the numeric list, you can
use it with the GetString function to get the text associated with that
item. Here is a pasted in example from part of a GUI sub from an app I have
that will take the selected items a -multisel listbox. I place this event
handler inside the subroutine that contains the GUI. I did that so that the
@_ from the GUI sub is accessible without passing anything explicitly (That
may work with it outside. I'm not sure about that part, but I know it works
with it inside the GUI subroutine). I am using references because I am
populating multiple arrays from the GUI's sub:

# define the listbox:

    my $tb2 = $disp->AddListbox (
          -name                 =>         'DeptsList',
          -height                       =>         $disp->ScaleHeight() -
100,
          -width                        =>         $disp->ScaleWidth() - 40,
          -pos                  =>         [20,40],
          -addstyle                     =>         WS_VSCROLL,
          -multisel                     =>         2,  
          );

        my @button;
    $button[0] = $disp->AddButton (
          -name                   =>      'submit3',
          -text                   =>      'Submit',
          -height                         =>      20,
          -width                          =>      50,
          -pos                    =>      [$disp->ScaleWidth()/4 - 25,
$disp->ScaleHeight() - 40],
          );
        $button[1] = $disp->AddButton (
          -name                 =>                'cancel3',
          -text                 =>                'Cancel',
          -height                       =>                20,
          -width                        =>                50,
          -pos                  =>        [3*($disp->ScaleWidth()/4) - 25,
$disp->ScaleHeight() - 40],
          );

# finish building the GUI, then handle the Click event as so:
        
sub submit3_Click {
                # put the list indexes into the lexical @selected array:
                my @selected = $tb2->SelectedItems();

                # make it so nothing happens if nothing is selected:

                if ($selected[0] eq '') {
                   return;
                   }
                foreach (@selected) {
                        # use the GetString function to get the text
                        # associated with the each index as it is processed.
                        # put these string items 
                        # in the fourth array passed by reference to the GUI
sub:

                        push (@{$_[3]}, $tb2->GetString($_));
                        }
                # destroy the GUI:

                return -1;
                }       


Hope all that retains some formatting through the mail, and hope that gets
you what you need.

Steve H.

-----Original Message-----
From: Steve Myers [mailto:[EMAIL PROTECTED]
Sent: Friday, December 28, 2001 6:46 AM
To: perl-win32-gui-users@lists.sourceforge.net
Subject: [perl-win32-gui-users] Assigning contents of single line
textbox to variable


I'm not really serious with creating GUI applications for PERL, I just found

Win32 GUI to be a pretty cool module, and at the time have the need for a 
small GUI app thats a workaround for something.

I've created numerous single line text boxes where the user may input text, 
I'd like to assign their current text to variables, and a large multi-line 
text box who's text I'd like to assign to an array.  It will use these 
values after they click an "OK" button, so it would assign the 
variables/array when they click it, to ensure getting the current value.

How would I do this?  I haven't really experimented or looked at sample 
code, this is just a early help thing, so in case I can't figure it out, 
maybe somebody will have already told me how.

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
- This message (including any attachments) contains confidential information
intended for a specific individual and purpose, and is protected by law.  -
If you are not the intended recipient, you should delete this message and
are hereby notified that any disclosure, copying, or distribution of this
message, or the taking of any action based on it, is strictly prohibited.

Reply via email to