|
-
August 27th, 2009, 05:32 AM
#1
help with picture box
Hello and good day...
I need to create a picturebox that allows different pics to show when The user clicks an item in a combo box. in vb.net.....
Any help on how to go about it is welcomed
-
August 27th, 2009, 07:00 AM
#2
Re: help with picture box
Hello, i have done a sample code for you.
Instructions
1. Pull a ComboBox (named ComboBox1) and a PictureBox (named PictureBox1) to the form
2. Copy the following code to the editor
3. Change the directory path that contains the images.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dirInfo As New System.IO.DirectoryInfo("C:\Users\Public\Pictures\Sample Pictures")
ComboBox1.DataSource = dirInfo.GetFiles("*.jpg")
ComboBox1.DisplayMember = "Name"
ComboBox1.Refresh()
UpdatePicture()
End Sub
Private Sub UpdatePicture()
If ComboBox1.SelectedIndex < 0 Then Exit Sub
Dim f As System.IO.FileInfo
f = CType(ComboBox1.SelectedItem, System.IO.FileInfo)
PictureBox1.Image = System.Drawing.Image.FromFile(f.FullName)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
UpdatePicture()
End Sub
-
August 27th, 2009, 08:56 AM
#3
Re: help with picture box
Thanks I got that working .... I already have a list of items in my combobox and I want Images to occur in the picture box area once its click........
-
August 27th, 2009, 08:30 PM
#4
Re: help with picture box
Have you copy this sub to the code editor
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Having this event, the picture box should load the picture when the combox item selection is changed.
By the way, what are your images extension?
-
August 27th, 2009, 10:05 PM
#5
Re: help with picture box
Thanks I have it solved already
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|