Solved

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

Posted on 2010-09-12
9
687 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

758 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

21 Experts available now in Live!

Get 1:1 Help Now