[Gambas-user] Arrays of controls..
Stephen Bungay
sbungay at ...981...
Fri Feb 11 21:18:22 CET 2011
Hi Matti!
Thanks for the reply.
OK, that also works when everything is all on in the one form
class. Let me clarify.
We have two forms, FMain and FormButtons. FMain has on it a TabStrip
container (TabStrip1) and nothing else. FormButtons has on it one (1)
Toggle Button called ToggleButton1 which serves as a test-case control
(we know that its event will trap).
FMain.class contains this logic (and only this logic)
' Gambas class file
PRIVATE ButtonForm AS FormButtons
PUBLIC SUB Form_Open()
TabStrip1.Index = 0
ButtonForm = NEW FormButtons(TabStrip1) AS "ButtonForm"
END
FormButtons contains this logic...
' Gambas class file
PUBLIC SUB Form_Open()
DIM X AS Integer
DIM ButtonArray[10] AS Object
DIM myToggleButton AS ToggleButton
FOR X = 0 TO 9
ButtonArray[X] = NEW ToggleButton(ME) AS "ToggleButtons"
WITH ButtonArray[X]
.X = 90 + (20 * x)
.Y = 100
.Width = 20
.height = 20
.tag = x
END WITH
NEXT
END
' This one does not trap
PRIVATE SUB ToggleButtons_click()
STOP
END
' This one does trap
PUBLIC SUB ToggleButton1_Click()
STOP
END
So what I expect to happen is that FormButtons has the ToggleButtons
dynamically created and placed on itself (this does happen), then it
in-turn gets placed on FMain inside TabStrip1 (this also happens), and
when one of the dynamically created toggle buttons is clicked the click
event "ToggleButtons_click" fires (this does NOT happen). However, if
one clicks on the button that is not dynamically created (ToggleButton1)
its event does fire and code execution encounters the STOP statement.
Try it out.
On 02/11/2011 11:35 AM, Matti wrote:
> First, put the buttons in a group that can catch events:
> ButtonArray[X] = NEW Button(ME) as "Buttons"
>
> Then, give every button an individual Tag:
> .height = 20
> .Tag = X
>
> And the event to see which one is clicked:
> Public Sub Buttons_Click() ' reacts to all the buttons
> Dim i As Integer
>
> i = Last.Tag 'reads the Tag, so you see which one it was
> Print i
>
> Select Case
> .....
> End Select
> End
>
>
>
> Am 11.02.2011 17:00, schrieb Stephen Bungay:
>> Given the following code (Gambas 2.22)
>>
>> PUBLIC SUB Form_Open()
>> DIM X AS Integer
>> DIM ButtonArray[10] AS Object
>>
>> FOR X = 0 TO 9
>> ButtonArray[X] = NEW Button(ME)
>> WITH ButtonArray[X]
>> .X = 90 + (20 * x)
>> .Y = 100
>> .Width = 20
>> .height = 20
>> END WITH
>> NEXT
>>
>> END
>>
>>
>> How then would one trap the events being raised by a click on one of
>> the buttons in ButtonArray[]?
>>
>> I'm assuming (a bad thing... I know) that the array 'ButtonArray'
>> persists after Form_Open completes and until the form is closed.
>>
>> ------------------------------------------------------------------------------
>> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
>> Pinpoint memory and threading errors before they happen.
>> Find and fix more than 250 security defects in the development cycle.
>> Locate bottlenecks in serial and parallel code that limit performance.
>> http://p.sf.net/sfu/intel-dev2devfeb
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb
> _______________________________________________
> 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