Open Images using combo box

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2008
Posts: 22
Reputation: asmit1987 is an unknown quantity at this point 
Solved Threads: 0
asmit1987 asmit1987 is offline Offline
Newbie Poster

Open Images using combo box

 
0
  #1
Sep 20th, 2008
I am having a combo box in my form and i want to open a image using that now whenever i select any option from the combo box different different images should be displayed what cud be the necessary code and what event should be used to write the necessary code for it plz guide with all necessary deatils along with a example code..
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: Open Images using combo box

 
0
  #2
Sep 20th, 2008
1/to use image in the form you need PictureBox Control
2/in order to change the picture whenever the user select item from the comboBox you use the SelectedIndexChanged event, you can get the item that user selected by
  1. dim selectedItem as string
  2. selectedItem = ComboBox.Text
Last edited by manal; Sep 20th, 2008 at 9:41 pm.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Open Images using combo box

 
0
  #3
Sep 20th, 2008
dim selectedItem as string
selectedItem = ComboBox.Text
why didn't use selectedItem = ComboBox.SelectedItem ?
and there are path on combobox item to loaded?
Last edited by Jx_Man; Sep 20th, 2008 at 11:50 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 22
Reputation: asmit1987 is an unknown quantity at this point 
Solved Threads: 0
asmit1987 asmit1987 is offline Offline
Newbie Poster

Re: Open Images using combo box

 
0
  #4
Sep 21st, 2008
i am opening the image frm the combo box the image is placed in a picture box now if my first item in the list be x then what code should be written to open the image in the picture box
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Open Images using combo box

 
0
  #5
Sep 21st, 2008
Do you store the file path in your combo box? Like this:

  1. ComboBox1.Items.Clear()
  2. ComboBox1.Items.Add("D:\Download\Image1.jpg")
  3. ComboBox1.Items.Add("D:\Download\Image2.jpg")

then you get the image with:

  1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  2. '
  3. ' Load picture from the file
  4.  
  5. Try
  6. PictureBox1.Image = Image.FromFile(ComboBox1.SelectedItem.ToString)
  7. Catch ex As Exception
  8. ' Handle exception
  9. End Try
  10.  
  11. End Sub

ComboBox1.SelectedItem is of the type object so you have to cast it to the string.
However, if you store "friendly names" in your combo box, you need some mapping to file names. Here's a one way to do that:

  1. Private ImagePaths() As String
  2.  
  3. ComboBox1.Items.Clear()
  4. ComboBox1.Items.Add("My dog")
  5. ComboBox1.Items.Add("My wife")
  6. ReDim ImagePaths(1)
  7. ImagePaths(0) = "D:\Download\Image1.jpg"
  8. ImagePaths(1) = "D:\Download\Image2.jpg"

and then you do the mapping to get the image:

  1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  2. '
  3. ' Load picture from the file
  4.  
  5. Try
  6. PictureBox1.Image = Image.FromFile(ImagePaths(ComboBox1.SelectedIndex))
  7. Catch ex As Exception
  8. ' Handle exception
  9. End Try
  10.  
  11. End Sub
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC