Question

Hi I am using visual studio 8, vb.net. I have a picture box on my form, picturebox1

I have a number of image files name image1.gif image2.gif image3.gif etc upto image52.gif

I want to display an image in a picturebox dependant upon a value wich is generated elsewhere in the app, so that if '3' is generated I a picturebox to display image3.gif if 2 is generated image2.gif. However I have 52 such images to be displayed in 16 picture boxes so I was wondering if there is a more efficient way than a select case method for each image and each picture box.

All and anyhelp is much appreciated thank you.

Was it helpful?

Solution

Whenever i have a large number of images i always use an imagelist. You could add the images to the list in the correct order and access the image at the desired index position.But it will help you get rid of one of the select statement but you will still need to have one for the different picture box. This is really only to keep things clean. Performance wise i am not sure you would get that much of a hit by doing multiple select statement.

OTHER TIPS

You can make a custom url to the image:

string ImageUrl = startofurl + GeneratedNumber + ".gif";

So if you use for example these values:

startofurl = "C:\Users\Wiebren\Desktop\image"
generatednumber = 4

You will get this:

url = "C:\Users\Wiebren\Desktop\image3.gif"

Do this for the 16 boxes and you are done.

Hope this will work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top