how to load an image to a form

Thread Solved

Join Date: Dec 2004
Posts: 116
Reputation: stackOverflow is an unknown quantity at this point 
Solved Threads: 0
stackOverflow's Avatar
stackOverflow stackOverflow is offline Offline
Junior Poster

how to load an image to a form

 
0
  #1
Feb 24th, 2005
Hi,

I have a problem. I have put up an image on a form of .jpeg format.(copy and pasted).. But when i save it... it works fine at home.. .when i copy it on a cd... it is not saving the background image. Rather ... when I try to open it on an other computer.. the background image is gone. I'm not finding any reason ..why thats happening.. i'd be glad if someone can help me. Should i save the image on the other computer too and give a path name or something using code?? If yes... what is the code like? Please help me. And why does it happen so? Thank you.Forgot to add this... i'm using vb6.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: how to load an image to a form

 
0
  #2
Feb 24th, 2005
There is a couple of solutions.... one is to put the picture in the same folder as the VB EXE that is going to be running it. And then use the code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. form1.picture = app.path & "\picturename.jpg"

Another alternative, is to use a picturebox.... and set it's attributes to hidden. Set it's pictures property to the image you want. You should be able to get away without having to move the file around everywhere. Copy and paste.... you should be able to paste it into a picture box... but I'm not positive. Anyway, if you use a picture box, you could set the form with:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. form1.picture = picture1.picture

Let me know what you think.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 238
Reputation: uniquestar is an unknown quantity at this point 
Solved Threads: 11
uniquestar's Avatar
uniquestar uniquestar is offline Offline
Daniweb Sponsor

Re: how to load an image to a form

 
0
  #3
Feb 25th, 2005
the best way to do it is to link to the file outside as said above, just ensure that the path is correct and always links to the right file.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: how to load an image to a form

 
0
  #4
Feb 25th, 2005
Well, That depends entirely on portability, and what you are after. If you want it to be contained within the EXE... so you don't have to try to keep track of such and such.jpg, then it would be better to do it in a picturebox. The drawback to this, is EXE file size, and loading time... but ultimately, it's a matter of what you are trying to accomplish.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 116
Reputation: stackOverflow is an unknown quantity at this point 
Solved Threads: 0
stackOverflow's Avatar
stackOverflow stackOverflow is offline Offline
Junior Poster

Re: how to load an image to a form

 
0
  #5
Feb 26th, 2005
Thanks a lot for your suggestions. I'll try and let you know soon. Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 116
Reputation: stackOverflow is an unknown quantity at this point 
Solved Threads: 0
stackOverflow's Avatar
stackOverflow stackOverflow is offline Offline
Junior Poster

Re: how to load an image to a form

 
0
  #6
Feb 27th, 2005
Hi again,

Can you tell me.. whats wrong with this code...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. Form1.Picture = App.Path & "\096.jpg"
  3. End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: how to load an image to a form

 
0
  #7
Feb 27th, 2005
There is nothing wrong with that code.... UNLESS:

1) the form that you are trying to load the image to is NOT called form1
2) the file "096.jpg" is NOT in the same folder as the EXE file you created.

Now, On the second note, (I don't remember the path, but you could do a msgbox app.path to find out), the file 096.jpg MUST BE IN THE SAME FOLDER as the program. If you make the program an EXE (file, make exe) then that EXE must be in the same folder as the picture file when the program runs, in order for it to work. If you are using the VB IDE (clicking start, and running it from within VB) then you'll have to know the path that it's running, and put the picture file there.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 116
Reputation: stackOverflow is an unknown quantity at this point 
Solved Threads: 0
stackOverflow's Avatar
stackOverflow stackOverflow is offline Offline
Junior Poster

Re: how to load an image to a form

 
0
  #8
Mar 3rd, 2005
Hi,

 Private Sub Form_Load()
Form1.Picture = App.Path & "\096.jpg"
End Sub

It is giving a compile error at & as type mismatch.

Where am i wrong . Please help.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: how to load an image to a form

 
0
  #9
Mar 3rd, 2005
K. Change the & to a +
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 116
Reputation: stackOverflow is an unknown quantity at this point 
Solved Threads: 0
stackOverflow's Avatar
stackOverflow stackOverflow is offline Offline
Junior Poster

Re: how to load an image to a form

 
0
  #10
Mar 3rd, 2005
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Form1.Picture = App.Path a + "\096.jpg"

its giving a syntax error
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC