[Gambas-user] Arrays of controls
tobias
tobiasboe1 at ...20...
Sun Aug 28 10:11:04 CEST 2011
hi,
> I do not check this at all:
>
> Public Sub Page_First_Init()
> Dim hPictureBox As PictureBox
> Dim I As Integer
> For i = 0 To 9
> hPictureBox = New PictureBox(Me) As "PBX"
> hPictureBox.Tag = i
> Next
> End
ok, you have a loop from 0 to 9 in which you create PictureBoxes by
using New, each of them gets the event name "PBX" and a tag to identify
them.
those PictureBoxes are created on Me and therefore now normal controls.
you additionally hold a reference to the just created one in hPictureBox
so you can change its attributes as you want:
hPictureBox.Visible = False
you can pick a particular box using Me.Children (i don't know, if this
is the best solution for it):
Public Function Pick(iInd As Integer) As PictureBox
Dim cControl As Control
For Each cControl In Me.Children
If Object.Type(cControl) = "PictureBox" And cControl.Tag = iInd Then
Return cControl
Endif
Next
Return Null
End
the thing with this is that Tags may be set arbitrarily, so checking if
the control is also a PictureBox is a little more secure not to give
something wrong back but keep in mind that for some reason, you may have
given another PictureBox the same Tag which leads to giving back the
first one recognized in Me.Children... (according to the doc, the Tag
property of Controls aren't used by any component but only by the
programmer, so you might take this solution with care or derive another
one from it.
for a different approach, you may have a look at the ArrayOfControls
example.
within an event raised by the PBX "group" you can just use Last.
i hope, it's somehow clearer, now?
regards,
tobi
More information about the User
mailing list