Results 1 to 3 of 3

Thread: Create New Objects Just Using Code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    117
    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?

  2. #2
    Member
    Join Date
    Oct 1999
    Posts
    51
    yeah, make a dynamic array of the image object using:

    Dim MyImages() as Image

    Then you can keep redimming the array when needed.

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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:

    Code:
    '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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width