[Gambas-user] how to place code into events of an array of buttons?
Gianluigi
bagonergi at gmail.com
Tue Feb 1 19:20:43 CET 2022
Il giorno mar 1 feb 2022 alle ore 18:51 <roberto.premoli at tiscali.it> ha
scritto:
> > Change Form_Open like this
> > ' ...
> > matrice_testo[0] = "A"
> > matrice_testo[1] = "B"
> > matrice_testo[2] = "C"
> > matrice_testo[3] = "D"
> > matrice_testo[4] = "E"
> >
> > For n = 0 To 4
> > With btns[n] = New Button(FMain) As "btns"
> > .Name = matrice_testo[n]
> > End With
> > Next
> > ' ...
> >
> > Public Sub btns_Click()
> > Print Last.name
> > End
> >
> > Regards
> > Gianluigi
>
> Thanks Gianluigi!
> there is a way to take also the index of button pressed?
> because to have the index of button is necessary in other part of the
> program,
> I tried - naively - to do "variabile = Last.index" bot of course it
> does not work.
>
> If it is not possible, i can populate ".tag = n" and read it but it
> will appear
> to me more "clean" to use ".index" or similar, if available.
> Roberto
>
> PS: i miss so much to have "indexed objects" in Gambas graphical
> interface as it
> is available in VB.
>
Sorry I read your post superficially.
The code is right even as you wrote it, you just need to use Last (i.e.
Last.Text) to know which button raised the event
For index, If you set the name as "n" e.g.
For n = 0 To 4 'first line'
btns[n].Name = n
...
you can use
Print FMain[3].Font.Bold
Regards
Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220201/e16f8289/attachment.htm>
More information about the User
mailing list