| | |
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 |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application array arrays basic beginner browser button buttons center checkbox client code convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel fade filter forms ftp generatetags gridview html images inline input insert intel internet lib listview mobile monitor net objects open panel passingparameters pdf picturebox port position print printing problem read remove save searchvb.net select serial settings shutdown soap sorting sqlserver survey table temperature textbox timer timespan transparency trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web webbrowser winforms wpf wrapingcode year






