Sunday, April 26, 2009

Using VB Resources

A more effective way of displaying images in your Cats and Dogs 2 program, (or any other program), would be to utilise the resources feature of Visual Studio. To do this right click on CatsAndDogs2 project in Solution Explorer and select properties. Click resources on the left and then the little arrow next to Add Resource, and choose Add Existing File. Navigate to your files and open them all. Now they are stored in your resources.
To use them in your Cats and Dogs 2 program you need to open your dog class; and in the Private Sub CreateArray() method; instead of using:
_imgPictures(0) = Image.FromFile("G:\Visual Studio\CatsAndDogs2\CatsAndDogs2\slides\1.gif")
You can get your image from the resources by coding:
_imgPictures(0) = My.Resources._1()
Repeat this for all images in your array and then do the same thing for the cat class.
Doing this will allow your program to find your images no matter if you move the program to another location.

2 comments:

  1. Good one Craig. I have featured your post on my blog :)

    ReplyDelete
  2. Awesome stuff Craig. Wish I'd read this a few (read about 6) hours earlier than I did. Would have saved me heaps of trouble.

    Well done!

    ReplyDelete