PDA

Click to See Complete Forum and Search --> : Create New Objects Just Using Code


royjacob
Aug 16th, 2000, 10:38 AM
I'm trying to create a game where the number of Image Objects in the Form varies according to what the user does and how long he plays the game.
So, does anyone know how to insert new image objects, preferably arrayed, using just code as supposed to dragging it into the form during design time?

kl899
Aug 16th, 2000, 10:49 AM
yeah, make a dynamic array of the image object using:

Dim MyImages() as Image

Then you can keep redimming the array when needed.

Fox
Aug 16th, 2000, 11:13 AM
Well, the easiest way is when you create one
at design time and set it's index to 0. You
can load instances of this object in runtime
afterverbs:


'Add a picture box to a new project and
'set it's "Index" property to 0. Also
'add this code, then run the project.

Private Sub Form_Load()
Dim A As Long

For A = 0 To 10
'Load new control if necessary
If A > 0 Then: Load Picture1(A)

With Picture1(A)
'Randomize position and size
.Move Me.ScaleWidth * Rnd, Me.ScaleHeight * Rnd, Me.ScaleWidth / 3 * Rnd, Me.ScaleHeight / 3 * Rnd

'Set random color
.BackColor = 16777215 * Rnd

'Finally show it
.Visible = True
End With
Next
End Sub