|
-
Mar 10th, 2010, 10:02 PM
#1
Thread Starter
Member
[RESOLVED] Opening images with ListBox
Hello, I have a ListBox.
When I load up an image, a entry in added to the ListBox with the location of the image file. I also have a PictureBox... when you click a item in the listbox, I need the PictureBox to load the image associated with the ListBox entry.
I tried this, but of I course it didn't work:
Private Sub import_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles import.Click
Dim dlg As DialogResult = openfile.ShowDialog()
Dim filename As String = openfile.FileName
Images.Items.Add(filename)
Dim selectpic = New Bitmap(Images.SelectedItem.Text)
PictureBox1.Image = selectpic
End Sub
Now I know this is incorrect:
Dim selectpic = New Bitmap(Images.SelectedItem.Text)
But I am stumped on what to do, can I set a variable for each new entry which contains the image?
-
Mar 10th, 2010, 10:47 PM
#2
Re: Opening images with ListBox
So the ListBox contains the path to the image right?
vb.net Code:
PictureBox1.Image = Image.FromFile(Images.SelectedItem.ToString)
-
Mar 10th, 2010, 10:53 PM
#3
Re: Opening images with ListBox
 Originally Posted by formlesstree4
So the ListBox contains the path to the image right?
vb.net Code:
PictureBox1.Image = Image.FromFile(Images.SelectedItem.ToString)
Assuming that the ListBox contains Strings in the first place:
vb.net Code:
PictureBox1.Image = Image.FromFile(Images.Text)
-
Mar 11th, 2010, 01:58 PM
#4
Thread Starter
Member
Re: Opening images with ListBox
Thanks, works great. Only thing is, you always have to have a image selected or you'll get a ArgumentException error.
-
Mar 11th, 2010, 06:46 PM
#5
Re: Opening images with ListBox
 Originally Posted by iMiles
Thanks, works great. Only thing is, you always have to have a image selected or you'll get a ArgumentException error.
That would be what validation is for. Test that an item is selected before using the selected item.
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
|