Hi,

I didn't test the below, but it should help. You need to do something like:

sub Button_Clicked{
  my $self = shift;  #$self now contains the button object - so you can call 
methods on it...
  print $self->Text(); 
  $Main->Status3->Text($self->Name); #not sure if there is a method called 
name...
}

Cheers,

Jeremy.

________________________________
From: [EMAIL PROTECTED]
To: perl-win32-gui-users@lists.sourceforge.net
Date: Fri, 21 Mar 2008 07:49:03 -0400
Subject: [perl-win32-gui-users] Button onClick event, how to get button -name



I have been trying to understand how to get the -name of a
button that was clicked by the -onClick event, at the subroutine.



I have read the win32::Gui docs over and over, read
several post here and elsewhere, but I still don't get it yet. :)

Please bear with me, I am trying to learn, but you know how
that goes. You don't get it and then all of a sudden it's all perfectly clear
and you wonder why you thought it was that difficult to begin with. My brain
seems to work really well by looking at working examples and then figuring out
how things work, but I haven't found a written working example of this on the
web so far and I didn't see an example in the win32::gui folders in my perl
install.



Anywho. here is what I have, please be gentle :)



I am creating a bunch of buttons on the fly from an array that
is read from a file.

All the buttons go to the same subroutine

At the subroutine I want to know the -name of the button that
was pressed and then go from there once I know the button -name.

I have no problem getting all the buttons to display and go to
the sub, the code all seems to work fine.



Here's the basics of the button code and the button onClick
sub

$Main is my window

$ButtonName comes from an array using a foreach loop and is a
unique name

$ButtonNumber comes from an array and is a unique name but not
the same as $ButtonName



### create buttons
###########################################

$ButtonNumber = new Win32::GUI::Button($Main,
-name =>
"$ButtonName",
-tip => "$ButtonName",
-pos => [$posX,
$posY],
-size => [15, 15],
-onClick =>
'Button_Clicked',
);





### sub that all buttons go to ###

sub Button_Clicked{



?????????????????????????? get button -name here.
:P



$Main->Status3->Text("$ButtonName");## display button
name in status bar
}

#########################################################



I have read this a million times but don't understand how to
proceed.

"The first parameter passed to the subroutine is a reference
to the object on which the event occured."

That's where I am lost, how exactly do I get
the first parameter (-name) in the form of a scalar?
Can anyone help me
with a bit of code in where my question marks are so I can get a handle on
this and stop pulling out my hair. :)



Thanks so much for any assistance

Doug


_________________________________________________________________
Welcome to the next generation of Windows Live
http://www.windowslive.co.uk/get-live
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to