Solved

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

Posted on 2010-09-12
9
692 Views
Last Modified: 2012-05-10
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
Comment
Question by:RobertoFreemano
  • 3
  • 3
  • 3
9 Comments
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 50 total points
ID: 33657983
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 100 total points
ID: 33658032
*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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33658075
@Idle...Your code is not Correct because does not worth 100 point!!!!!! :)   i am only fooling! :))
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33658125
Haha...I never really pay attention to the points on the question.  Did I give too much code for 100 pts?...  =)
0
 

Author Comment

by:RobertoFreemano
ID: 33658132
Not sure why, but neither solutions worked :(

This means, the problem must lie with me.

PictureBox1 is just blank.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33658142
Did You Check The existance Of Images in your Image List?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33658403
Can you post your code along with the NAMES of your ImageList, PictureBox and Buttons?
0
 

Author Comment

by:RobertoFreemano
ID: 33659841
Thanks Guys... It was me!!!!! I was trying to get it working with PNG images (DOH), so I changed them to BMP ;)
0
 

Author Closing Comment

by:RobertoFreemano
ID: 33659846
Thanks Guys
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question