change picture-box image stored in my Image-List vb.net 2003

HI Experts,

I have a WINFORM,1 Image-List, 1 Picture-box and a button... In the Image-List, I have several pictures... (1) = (7)..etc..

I've seen several examples for doing this from a file-path... if I had 1 Picture-box and 4 buttons... then each button would pick an image from my Image-List and occupy the Picture-box.

Thanks,
Roberto
RobertoFreemanoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
*Assuming your Buttons are named Button1 --> ButtonXXX so we can strip the "Button" part from the beginning and get an "Index" for each one.

You can use the Handles keyword to make ALL the buttons fire the same handler...just list them all after the "Handles" keyword.  Then you can change the Image being used from the ImageList based on the Button that was clicked.

Something like this to make it generic:
    Private Sub AllButtons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click
        Dim btn As Button = CType(sender, Button)
        Dim btnIndex As String = btn.Name.ToLower.TrimStart("button".ToCharArray)
        Dim index As Integer
        Try
            index = Integer.Parse(btnIndex) - 1
            If index >= 0 And index < ImageList1.Images.Count Then
                PictureBox1.Image = ImageList1.Images(index)
            End If
        Catch ex As Exception
        End Try
    End Sub

Open in new window

0
 
John (Yiannis) ToutountzoglouConnect With a Mentor Instructor Multiengine PilotCommented:
in the button1 click set this piece of code

PictureBox1.Image = ImageList1.Images.Item(0)   'It is Zero based .This will get the firs picture of your image List.Do the same for the other buttons

Open in new window

0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
@Idle...Your code is not Correct because does not worth 100 point!!!!!! :)   i am only fooling! :))
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Haha...I never really pay attention to the points on the question.  Did I give too much code for 100 pts?...  =)
0
 
RobertoFreemanoAuthor Commented:
Not sure why, but neither solutions worked :(

This means, the problem must lie with me.

PictureBox1 is just blank.
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Did You Check The existance Of Images in your Image List?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Can you post your code along with the NAMES of your ImageList, PictureBox and Buttons?
0
 
RobertoFreemanoAuthor Commented:
Thanks Guys... It was me!!!!! I was trying to get it working with PNG images (DOH), so I changed them to BMP ;)
0
 
RobertoFreemanoAuthor Commented:
Thanks Guys
0
All Courses

From novice to tech pro — start learning today.