| | |
Open Images using combo box
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 22
Reputation:
Solved Threads: 0
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..
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
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
VB.NET Syntax (Toggle Plain Text)
dim selectedItem as string selectedItem = ComboBox.Text
Last edited by manal; Sep 20th, 2008 at 9:41 pm.
"give only what u willing to receive "
•
•
•
•
dim selectedItem as string
selectedItem = ComboBox.Text
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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
Do you store the file path in your combo box? Like this:
then you get the image with:
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:
and then you do the mapping to get the image:
VB.NET Syntax (Toggle Plain Text)
ComboBox1.Items.Clear() ComboBox1.Items.Add("D:\Download\Image1.jpg") ComboBox1.Items.Add("D:\Download\Image2.jpg")
then you get the image with:
VB.NET Syntax (Toggle Plain Text)
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged ' ' Load picture from the file Try PictureBox1.Image = Image.FromFile(ComboBox1.SelectedItem.ToString) Catch ex As Exception ' Handle exception End Try 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:
VB.NET Syntax (Toggle Plain Text)
Private ImagePaths() As String ComboBox1.Items.Clear() ComboBox1.Items.Add("My dog") ComboBox1.Items.Add("My wife") ReDim ImagePaths(1) ImagePaths(0) = "D:\Download\Image1.jpg" ImagePaths(1) = "D:\Download\Image2.jpg"
and then you do the mapping to get the image:
VB.NET Syntax (Toggle Plain Text)
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged ' ' Load picture from the file Try PictureBox1.Image = Image.FromFile(ImagePaths(ComboBox1.SelectedIndex)) Catch ex As Exception ' Handle exception End Try End Sub
Teme64 @ Windows Developer Blog
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Procdedure for sending sms using vb.net 2005 help
- Next Thread: Using Graphics
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary box button buttons center click code combo combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog search serial sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter updown useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml






