Solved

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

Posted on 2010-09-12
9
691 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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.

856 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