changing picturebox.image using text from listbox

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 5919 Views - Last Post: 23 December 2011 - 10:23 PM Rate Topic: -----

#1 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

changing picturebox.image using text from listbox

Posted 16 December 2011 - 02:12 AM

Private Sub lstTitle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTitle.SelectedIndexChanged
        Dim Title As String = lstTitle.Text
        Dim Locate As String = Application.StartupPath
        picImage.Image = Locate & Title & ".jpg"
End Sub 


okay, so what i am trying to do is every time the user changes their selection in the ListBox the PictureBox will change accordingly. Its not quite working, i have tried multiple things even a Select Case method but its not what i was after. Can someone please help me. Thank you In Advance.

Is This A Good Question/Topic? 0
  • +

Replies To: changing picturebox.image using text from listbox

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: changing picturebox.image using text from listbox

Posted 16 December 2011 - 02:23 AM

picImage.Image is a property of type Image and you try to assign a string into it. That's just impossible. You have to assign an Image to the picImage.Image.

This should work but I didn't test it:
picImage.Image = System.Drawing.Image.FromFile(Locate & Title & ".jpg")


Was This Post Helpful? 0
  • +
  • -

#3 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: changing picturebox.image using text from listbox

Posted 16 December 2011 - 02:27 AM

Never Mind, Figured it out, Fairly simple when i look back at it now.

all i had to do was to change this line of code.

picImage.ImageLocation = Locate & "\" & Title & ".jpg"


Thanks anyways

View Postjanne_panne, on 16 December 2011 - 02:23 AM, said:

picImage.Image is a property of type Image and you try to assign a string into it. That's just impossible. You have to assign an Image to the picImage.Image.

This should work but I didn't test it:
picImage.Image = System.Drawing.Image.FromFile(Locate & Title & ".jpg")


^^^^ This method worked just need to put in the "\" part of it. Although, my way does not give an error it just makes the picturebox have a x in it. Yours throws you out of the program and gives an error.

Thanks anyways mate.
Was This Post Helpful? 1
  • +
  • -

#4 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: changing picturebox.image using text from listbox

Posted 16 December 2011 - 06:44 AM

That's true, System.Drawing.Image.FromFile will throw a FileNotFoundException if it can't find the file so checking the file existence with System.IO.File.Exists() method is required.

Using ImageLocation property was a good idea, didn't cross my mind :)
Was This Post Helpful? 0
  • +
  • -

#5 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: changing picturebox.image using text from listbox

Posted 16 December 2011 - 01:50 PM

@janne_panne:
You don't need to use System.Drawing.Image.FromFile; I find that I can call this instead: Image.FromFile
Was This Post Helpful? 0
  • +
  • -

#6 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: changing picturebox.image using text from listbox

Posted 19 December 2011 - 01:05 AM

thanks for the great advice, jimmybo <-> i have not tried your method, but i found that mine works just fine so will stay with that. Thanks heaps anyways, and if you really thought mine was a good idea can you please give a +. i don't know what they are for but i just want more. cheers.
Was This Post Helpful? 0
  • +
  • -

#7 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: changing picturebox.image using text from listbox

Posted 19 December 2011 - 04:59 AM

@jimmyBo:
It's the same method. If your code file has "using System.Drawing;" at the top of it, just writing "Image.FromFile" is enough to call the "System.Drawing.Image.FromFile" method.
Was This Post Helpful? 0
  • +
  • -

#8 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: changing picturebox.image using text from listbox

Posted 19 December 2011 - 05:53 PM

That's what I meant!
Was This Post Helpful? 0
  • +
  • -

#9 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: changing picturebox.image using text from listbox

Posted 22 December 2011 - 12:19 AM

janne_panne <- now that we have the other part working i am stuck on getting this part working now! I think its because the lstTitle.text is classed as FileNames as thats what we got from the directory. Please confirm this.

Here is the code.

, OMG i just figured it out, for some reason this was deleted at the end of the private sub
'Handles lstTitle.SelectedIndexChanged'
i have no idea why or how but its working flawlessly now. THANKYOU SO MUCH!
Was This Post Helpful? 0
  • +
  • -

#10 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: changing picturebox.image using text from listbox

Posted 22 December 2011 - 04:12 AM

Great, Now i have another problem!!

        Dim Title As String = lstTitle.Text
        Dim HomeLocation As String = Application.StartupPath & "\games\"
        Dim DNOLocation As String = Application.StartupPath & "\games\Do Not Open\"

        If Title < picImage.ImageLocation Then
            picImage.ImageLocation = HomeLocation & Title & ".jpg"
        Else
            picImage.ImageLocation = DNOLocation & Title & ".jpg"
        End If

what im trying to achieve is self explanatory if you can understand it. but here is a short version. There are 2 folder (Games) & (Games\Do Not Open). Now if the lsttitle.text cannot locate the image in the Games folder i want it to try and check the Games\Do Not Open folder. I thought an If Statement would suffice but im thinking not. Any suggestions?
Was This Post Helpful? 0
  • +
  • -

#11 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: changing picturebox.image using text from listbox

Posted 23 December 2011 - 06:19 PM

also the program is only getting the first 25-30 covers, when there are around 80, any suggestions on why it would be doing this?
Was This Post Helpful? 0
  • +
  • -

#12 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,499
  • Joined: 16-March 11

Re: changing picturebox.image using text from listbox

Posted 23 December 2011 - 07:27 PM

Try System.IO.File.exists or File.exists if you have the namespace included in your project.
Was This Post Helpful? 0
  • +
  • -

#13 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: changing picturebox.image using text from listbox

Posted 23 December 2011 - 08:39 PM

Trevster - spot on!
It would be something like this:
If IO.File.Exists(homedir + title) = True Then
'yay!
ElseIf IO.File.Exists(dnodir + title) = True Then
'yay2!
Else
'it doesn't exist
End If


I don't see code to retrieve covers, PNjLJ, so can you provide this please?
Was This Post Helpful? 0
  • +
  • -

#14 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: changing picturebox.image using text from listbox

Posted 23 December 2011 - 09:38 PM

View PostjimmyBo, on 23 December 2011 - 08:39 PM, said:

Trevster - spot on!
It would be something like this:
If IO.File.Exists(homedir + title) = True Then
'yay!
ElseIf IO.File.Exists(dnodir + title) = True Then
'yay2!
Else
'it doesn't exist
End If


I don't see code to retrieve covers, PNjLJ, so can you provide this please?


This here is the code to get the covers. They are on the Drive also.

Dim Title As String = lstTitle.Text
Dim HomeLocation As String = Application.StartupPath & "\games\"
Dim DNOLocation As String = Application.StartupPath & "\games\Do Not Open\"

If Title < picImage.ImageLocation Then
    picImage.ImageLocation = HomeLocation & Title & ".jpg"
Else
    picImage.ImageLocation = DNOLocation & Title & ".jpg"
End If


Was This Post Helpful? 0
  • +
  • -

#15 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,499
  • Joined: 16-March 11

Re: changing picturebox.image using text from listbox

Posted 23 December 2011 - 09:41 PM

How can a string be less than a string? Are you referring to the length? What's going on there?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2