[Gambas-user] Trapping events from dynamically created controls....

sbungay sbungay at ...981...
Tue Feb 20 20:12:26 CET 2007


   Thank you Timothy!

   I was appending an index number to the end of the button name like so

bh = NEW Button(LAST) AS "SkillButton" & CSTR(IndexID)

   My thinking was that the button names all had to be unique. Wrong wrong.

   Benoit, how can Gambas allow us to create controls on the fly that 
all have the same name when the IDE does not? It gives me the results I 
want and that's great, now I'm just wondering how this works internally.

Steve.


timothy wrote:
>>-----Original Message-----
>>From: gambas-user-bounces at lists.sourceforge.net [mailto:gambas-user-
>>bounces at lists.sourceforge.net] On Behalf Of sbungay
>>Sent: Tuesday, 20 February 2007 04:01 AM
>>To: gambas-user at lists.sourceforge.net
>>Subject: [Gambas-user] Trapping events from dynamically created
>>controls....
>>
>>   How can one capture events from controls that are created on the
> 
> fly?
> 
>>In my case I am creating buttons and want to capture the mousemove
> 
> event
> 
>>or click event of the control that was just created.
>>I think if I was able to add each programatically created control to a
>>special group then that group could capture and process the events. Is
>>this possible?
>>
>>Steve.
>>
> 
> 
> 
> Here is an example that creates a number of buttons and places them on a
> form. We create a new button, the ME parameter to NEW tells the button
> which container it should live in. You could use any other container
> e.g. a ScrollView. The AS "KeyButton" gives us the name to use when
> handling the buttons events. We also set some other properties of the
> button.
> 
> We have set the Form.Arrangement property to make the buttons look a bit
> nicer for this example.
> 
> The button click event is handled by the KeyButton_Click procedure -
> this must match the AS "KeyButton" statement. We get the button object
> using the LAST keyword. Here we just display the Name and Tag using a
> Message box.
> 
> ***************
> 
> PUBLIC SUB Form_Open()
>   DIM b AS Button
>   DIM i AS Integer
>   ' Fill the form with buttons for
>   ' ASCII codes 33 to 126
>   FOR i = 33 TO 126
>     b = NEW Button(ME) AS "KeyButton"
>     b.Font.Size = 32
>     b.Width = 56
>     b.Height = 56
>     IF Chr(i) LIKE "&" THEN
>       b.Text = "&&"
>     ELSE
>       b.Text = Chr(i)
>     END IF
>     b.Tag = i
>     b.ToolTip = "ASCII: 0x" & Hex(i, 2)
>   NEXT
>   ' Set the form arrangement so the buttons
>   ' fill the form area right to left. Note thet
>   ' when you resize the form the button fill the
>   ' available space
>   ME.Arrangement = Arrange.LeftRight
> END
> 
> ' Handle button click event
> PUBLIC SUB KeyButton_Click()
>   Message.Info("Button Tag: " & LAST.Tag & "\nButton Text: " &
> LAST.Text)
> END
> 
> ******************
> 
> From: http://www.linuxbasic.net/index.php?topic=117.0
> 
> Thanks
> 
> 8-{)} Timothy Marshal-Nichols
> <mailto: timothy.marshal-nichols at ...247...>
> 
>  
> 
> 
> 
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 




More information about the User mailing list