Solved

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

Posted on 2010-09-12
9
688 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now