0

Hi I have 60 picture boxes on a form, I want to update these images using a for loop. I have tried

Dim PCB as Image    
    For i = 1 to 60
        PCB(i).Image = mySampleProject.My.Resources.TestPCB1
     next

but get an error "Class 'System.Drawing.Image' cannot be indexed because it has no default property"
Does anyone have any idea how to solve this?
Thanks

4
Contributors
3
Replies
11
Views
9 Months
Discussion Span
Last Post by Reverend Jim
0

You declare PCB as an Image.
You cannot loop through an image that way, as you do in the following lines with PCB(i)

1

You can loop through all of the pictureboxes by

For Each pbx As PictureBox In Me.Controls.OfType(Of PictureBox)()
    pbx.Image = ...
Next

or if you have named them with the same prefix followed by a number like PictureBox1, PuctureBox2, etc. then you can access them by name as

Dim pbx As PictureBox
.
.
.
pbx = Me.Controls("PictureBox" & i)

as long as you give i a value beforehand. If you are creating code for PictureBox events you can use the same handler for all similar events.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.