CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Object Array

  1. #1
    Join Date
    Jul 2008
    Posts
    52

    Object Array

    I have a form with a lot of PictureBoxes. I created an array of these by name, but when I index the array I cant assign an image to the indexed item. In fact all the indexes appear to be nothing. Is there a way to create an array of controls and access them from the array?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Object Array

    Control array of them? Please be descriptive, and add some of your code, so we know what you've tried.
    Code:
    ' Use CODE TAGS like this
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Object Array

    Paul, if I do this :
    Code:
    Public Class Form1
        Private PicBox(4) As PictureBox
        Private i As Integer
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            PicBox(i) = New PictureBox
    
            PicBox(i).Image = Image.FromFile("C:\" & i.ToString & ".bmp")
            PicBox(i).Visible = True
            PicBox(i).BorderStyle = BorderStyle.FixedSingle
            PicBox(i).Left = 20 * (i * 2)
            Me.Controls.Add(PicBox(i))
            i = i + 1
        End Sub
    End Class
    It seems to work fine
    Can you show us your code, and how you implemented it perhaps ¿

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

Featured