Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pictures and icons 1

Status
Not open for further replies.

tg2003

IS-IT--Management
Feb 6, 2003
270
0
0
IL
Hello all,

I write a VB6 application that uses pictures and icons and it works well.

Now, when I try to check it from another environment (on another machine), I see that VB cannot find the pictures and icons, and I have to configure it again.

How can I set it so the pictures will not be path-depend? I know that there is an option of using resource file or something like that, but never tried it. Is it a solution for this scenario?

Thanks in advance!
 
Assuming that your pictures and icons are being loaded when you run your application (hence they don't appear on another machine), there are various solutions.

1. Instead of saying in your code (for example) Picture1.Picture = LoadPicture("c:\my app\images\logo.jpg"), say something like Picture1.Picture = LoadPicture(App.Path & "\images\logo.jpg"). This will then load a picture based on the location of your application. When you copy your application onto another machine, you only need to copy the images across too and it will be able to find them.

2. Check out the ImageList control which ships with VB, it's part of the Microsoft Windows Common Controls. This can be used to hold your icons for example, and then when you want to use one you can say Picture1.Picture = ImageList1.ListImages("icon_name_here").Picture. (This is just an example, you can do much more with an ImageList control such as transparencies and so on). ImageLists are geared more towards small images such as toolbar buttons and icons - if your pictures are large then that's probably not the answer.

3. Simply store your images in a hidden array of picture boxes. At design time, create a picture box, load a picture into it and set the Visible property to false. When you want to show it, you can either transfer the image into the picture box that is visible to the user by saying Picture1.Picture = PictureHidden(3).Image, or simply change the Visible property to True so that the user then sees the image.

4. Yes, you can use a resource file but that's probably the most technical of all three solutions because you need to independently compile a resource file and then add it into your VB application. However it's also the neatest solution.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
>independently compile a resource file

Er ... what do you mean by this?
 
Only that a resource file needs to be compiled separately using rc.exe - doesn't it? That's how I do it anyway, if there's an easier way the perhaps my method dates back to a version of VB before it was done some other way!

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
I had a nasty feeling you meant that. No, VB has a built-in resource editor which will compile the resource file into your VB app.

Step 1:
Add-Ins/Add-in Manager
Scroll to find and highlight VB 6 Resource Editor
Check "Loaded/Unloaded" and "Load on Startup" under Load Behaviour

And thats it. You will now find "Add New Resource file" under the Project menu; "Resource Editor" under tools, and "Resource File" under the "Add" submenu on the right-click menu for the Project Explorer
 
Thanks. It always seemed rather inelegant!

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top