• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 704
  • Last Modified:

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
0
RobertoFreemano
Asked:
RobertoFreemano
  • 3
  • 3
  • 3
2 Solutions
 
John (Yiannis) ToutountzoglouInstructor 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
 
Mike TomlinsonMiddle 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) ToutountzoglouInstructor Multiengine PilotCommented:
@Idle...Your code is not Correct because does not worth 100 point!!!!!! :)   i am only fooling! :))
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now