Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-12
9
Medium Priority
?
695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 200 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 86

Accepted Solution

by:
Mike Tomlinson earned 400 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

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 86

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

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!

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

688 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