creating a control array at run time

hi. how can i make a control array of 10 image controls at run time.
imean i wish to create 10 image controls at run time and they are named such that they are accessible using array notation like
img(0), img(1)...etc.
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You can't create a control array at runtime.

The way around this is to place one image control on your form with its index property set to 0.  Then when you need another control added to the array you can use the Load statement:

    Load Image1(Image1.Count) ' add one more to the control array


u cannot create a control array at run time but u can create a collection at run time...

u need to have atleast one control with index property set to 0 in design time , to create a control array at runtime
Here u need to place atleast one control as said by ANV and have to change the index prop to 0

for ex.,

place a command btn in a form and change its index property to 0 and run the code given below

it will create 10 btns

' To create 10 object start from 1 to 9 ( 1 obj placed already in the form)
    For i = 1 To 9        
'  creates  a obj in the form
       Load Command(i)                                                      
' by default visible is false for runtime created object so make it visible
       Command(i).Visible = True                                
'Moves the object to some place, by default all objects created at the same place. with out this all created objects stacked togethere
       Command(i).Top = Command(i).Top + i * 100

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.