Re: [Gambas-user] Control arrays
Brought to you by:
gambas
|
From: Rob <sou...@ku...> - 2003-07-21 00:00:23
|
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 c= ode, > in my specific case(labels)? I am new to not making an array graphicall= y. Setting the group of a control must be done at control creation time. Th= at=20 means, if you create the control graphically you need to do it graphicall= y=20 (in the Properties dialog) and if you want to set the group in code you a= lso=20 have to create the control in code. In your case you would want to do something like this, supposing 100x100=20 labels (please refer to one of the Tips of the Day which has the exact sy= ntax=20 for grouping, if mine doesn't compile): Public Labels as Object[] and then in the form load event handler dim tmpLabel as Label labels =3D new Object[] tmpLabel =3D new Label(ME) as "Labels" tmpLabel.Move(0,0,100,100) tmpLabel.Text =3D "text of label 0" labels.Add(tmpLabel) ' this will add label 0 tmpLabel =3D new Label(ME) as "Labels" tmpLabel.Move(100,0,100,100) tmpLabel.Text =3D "text of label 1" labels.Add(tmpLabel) ' this will add label 1 =2E.. tmpLabel =3D new Label(ME) as "Labels" tmpLabel.Move(200,200,100,100) tmpLabel.Text =3D "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() =09... your handler code... END Obviously it's a lot more code intensive than just being able to set the = index=20 in the form designer, but it can be done. It actually works much better = if=20 you have like a hundred controls to create because then it's more efficie= nt=20 to do it in a loop. =20 I guess what would be ideal as a workaround for the lack of design time=20 control arrays would be either (a) a collection or object array automatic= ally=20 populated with the contents of the corresponding group name, or (b) the=20 ability to add controls to a given array and set the index independently = of=20 the group feature. I think either could be implemented in the IDE (via c= ode=20 automatically generated and added to the form's class file) without needi= ng=20 changes to the language, if this proves unwieldy at the language level. = (a)=20 was pretty much how I mean to do it in my .frm to .form/.class converter=20 which isn't really doing much of use yet, but (b) would probably work bet= ter=20 for non-converted forms (since if you're converting from a VB project you= =20 already know which index each control is supposed to have.) Rob |