[Gambas-user] Control arrays
Rob
sourceforge-raindog2 at ...94...
Mon Jul 21 01:59:56 CEST 2003
On Sunday 20 July 2003 18:41, Ahmad Kamal wrote:
> Thnx A LOT, Rob, but could u plz show how to put them in a group with code,
> in my specific case(labels)? I am new to not making an array graphically.
Setting the group of a control must be done at control creation time. That
means, if you create the control graphically you need to do it graphically
(in the Properties dialog) and if you want to set the group in code you also
have to create the control in code.
In your case you would want to do something like this, supposing 100x100
labels (please refer to one of the Tips of the Day which has the exact syntax
for grouping, if mine doesn't compile):
Public Labels as Object[]
and then in the form load event handler
dim tmpLabel as Label
labels = new Object[]
tmpLabel = new Label(ME) as "Labels"
tmpLabel.Move(0,0,100,100)
tmpLabel.Text = "text of label 0"
labels.Add(tmpLabel) ' this will add label 0
tmpLabel = new Label(ME) as "Labels"
tmpLabel.Move(100,0,100,100)
tmpLabel.Text = "text of label 1"
labels.Add(tmpLabel) ' this will add label 1
...
tmpLabel = new Label(ME) as "Labels"
tmpLabel.Move(200,200,100,100)
tmpLabel.Text = "text of label 8"
labels.Add(tmpLabel) ' this will add label 8
Then when it's time to set the event handlers,
Public Sub Labels_Click()
... your handler code...
END
Obviously it's a lot more code intensive than just being able to set the index
in the form designer, but it can be done. It actually works much better if
you have like a hundred controls to create because then it's more efficient
to do it in a loop.
I guess what would be ideal as a workaround for the lack of design time
control arrays would be either (a) a collection or object array automatically
populated with the contents of the corresponding group name, or (b) the
ability to add controls to a given array and set the index independently of
the group feature. I think either could be implemented in the IDE (via code
automatically generated and added to the form's class file) without needing
changes to the language, if this proves unwieldy at the language level. (a)
was pretty much how I mean to do it in my .frm to .form/.class converter
which isn't really doing much of use yet, but (b) would probably work better
for non-converted forms (since if you're converting from a VB project you
already know which index each control is supposed to have.)
Rob
More information about the User
mailing list