944,150 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Feb 24th, 2005
0

how to load an image to a form

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
stackOverflow is offline Offline
116 posts
since Dec 2004
Feb 24th, 2005
0

Re: how to load an image to a form

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 25th, 2005
0

Re: how to load an image to a form

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.
Reputation Points: 49
Solved Threads: 11
Posting Whiz in Training
uniquestar is offline Offline
239 posts
since Feb 2005
Feb 25th, 2005
0

Re: how to load an image to a form

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 26th, 2005
0

Re: how to load an image to a form

Thanks a lot for your suggestions. I'll try and let you know soon. Thanks again.
Reputation Points: 10
Solved Threads: 0
Junior Poster
stackOverflow is offline Offline
116 posts
since Dec 2004
Feb 27th, 2005
0

Re: how to load an image to a form

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
Reputation Points: 10
Solved Threads: 0
Junior Poster
stackOverflow is offline Offline
116 posts
since Dec 2004
Feb 27th, 2005
0

Re: how to load an image to a form

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Mar 3rd, 2005
0

Re: how to load an image to a form

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster
stackOverflow is offline Offline
116 posts
since Dec 2004
Mar 3rd, 2005
0

Re: how to load an image to a form

K. Change the & to a +
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Mar 3rd, 2005
0

Re: how to load an image to a form

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Form1.Picture = App.Path a + "\096.jpg"

its giving a syntax error
Reputation Points: 10
Solved Threads: 0
Junior Poster
stackOverflow is offline Offline
116 posts
since Dec 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Text Box Newbie help
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB5 Company Name Version Info





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC