jccorner Posted September 6, 2004 Posted September 6, 2004 Maybe going about this the wrong way but I'm attempting to create a selectable list of images (.jpg and .gif) using the listbox, but every time I add one of the images, it just says System.Drawing.Bitmap in the list. Appreciate any help. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
Moderators Robby Posted September 6, 2004 Moderators Posted September 6, 2004 What method are you using to fill the list box? Quote Visit...Bassic Software
jccorner Posted September 7, 2004 Author Posted September 7, 2004 I'm not using a particular method, but here's the code: dim img as Image img = System.Drawing.FromFile(filename) Listbox1.Items.Add(img) Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
*Experts* Bucky Posted September 7, 2004 *Experts* Posted September 7, 2004 When you add the "img" variable to the Items collection, you are actually adding the image itself to the collection, but the ListBox can only display strings. By default, it uses the ToString() method of any object in the collection to display on the list. This is where the "System.Drawing.Bitmap" comes from. To remedy your problem, you'll need to keep track of a separate collection (something like an ArrayList) to store the actual pictures in. When you add items to the ListBox, instead of adding the Image itself, just add the file name, and add the Image to your separate collection. Make sure that when you add and remove file names from the listbox that you do the same to the image collection, so that the item indices of both collections match up. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
jccorner Posted September 7, 2004 Author Posted September 7, 2004 So, if listboxes can only display strings, then what control should I use to display the list. I am trying to create a list of thumbnail images that can be selected on and when selected, the image will appear on the main picturebox. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
MadMaxMSCN Posted September 7, 2004 Posted September 7, 2004 You need a listview and an imagelist. put your thumbnails in the imagelist. set the listview's "normal imagelist" property to your imagelist. the listview's view property must be set to 0 - lvwicon. when you add an item to your listview you can give it a name, that will be shown under your thumbnail and a number (the number of the picture in your imagelist). Quote
jccorner Posted September 7, 2004 Author Posted September 7, 2004 Great thanks, that worked. But one thing, how do I make the icons larger?? I set the view to large icon view but the thumbnail is not large enough to know what's inside. Is there a way to set the icon's size or change the size of the imagelist?? Thanks again. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
MadMaxMSCN Posted September 7, 2004 Posted September 7, 2004 You have to change the size in the ImageList. I never tested it in .net but in vb6 you had to change image size before adding the first image to the ImageList. In .net there's a property ImageList.ImageSize. I don't know if this is what you look for, but it looks good. Tell me if it works, max Quote
jccorner Posted September 7, 2004 Author Posted September 7, 2004 Yeah, I tried that but it asks for a System.Drawing.Size and I keep getting an error. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
*Experts* Bucky Posted September 7, 2004 *Experts* Posted September 7, 2004 Make sure the Height and Width of the ImageSize don't exceed 256; anything larger throws an ArgumentException. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
jccorner Posted September 8, 2004 Author Posted September 8, 2004 Okay, finally figured it out. Thanks everyone. I also tried the detail view but I can't make the images larger so I'll be going with the largeicon view. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.